• Python之matplotlib学习(四)


    例子12:ipython使用--pylab参数,默认加入matplotlib模块

    [root@typhoeus79 guosong]# ipython  --pylab
    WARNING: IPython History requires SQLite, your history will not be saved
    Python 2.7.3 (default, Nov 27 2012, 17:47:24) 
    Type "copyright", "credits" or "license" for more information.
    
    IPython 0.13.1 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    Welcome to pylab, a matplotlib-based Python environment [backend: agg].
    For more information, type 'help(pylab)'.
    
    In [1]: print matplotlib.__version__
    1.3.1

     例子13:输出多个图

    #!/usr/bin/env python2.7
    #-*- coding:utf8 -*-
    
    import os
    import sys
    
    import matplotlib as mpl
    mpl.use('Agg')#before importing pyplot
    
    import matplotlib.pyplot as plt
    from matplotlib.dates import datestr2num,DateFormatter
    
    import matplotlib.dates as dates
    import matplotlib.ticker as tk
    
    mpl.rcParams['figure.figsize'] = (12,16)
    
    
    sys.path.append("./lib")
    from mysql_base import MySQLBase
    
    
    def get_blog_size(cursor,size_port_list):
        data_size_list = []
    
        for size_port in size_port_list:
    
            sql = "select db_size,riqi from port_size where port = %s order by riqi DESC limit 60" % size_port
    
            cursor.execute(sql)
    
            result = cursor.fetchall()
    
            riqi_list = []
            db_size_list = []
    
            for row in result:
                riqi_list.append(str(row['riqi']))
                db_size_list.append(float(row['db_size']))
    
            riqi_list = riqi_list[::-1]
            db_size_list = db_size_list[::-1]
    
            data_size_tuple = (size_port,riqi_list,db_size_list)
            data_size_list.append(data_size_tuple)
    
        return data_size_list
    
    
    def draw(data_size_list):
    
        fig = plt.figure(2)
        idx = 411
      #第一位是行数,第二位是列数 for data_size in data_size_list: (port,riqi_list,db_size_list) = data_size ax=plt.subplot(idx) formatter = DateFormatter('%Y-%m-%d') ax.xaxis.set_major_formatter(formatter) plt.sca(ax) ax.plot_date(datestr2num(riqi_list),db_size_list,'-',label="(GB)") title = "%s_Data_Size" % port plt.title(title) plt.legend(loc='best') plt.grid(True) idx = idx + 1 plt.subplots_adjust(left=0.08, right=0.95, wspace=0.25, hspace=1) plt.savefig("blog_data_size.pdf",dpi=200) def main(): host = "XXXX" port = "xxxx" user = "xxx" passwd="xxxx" db = "xxx" conn = MySQLBase(host=host,port=port,user=user,passwd=passwd,db=db) cursor = conn.cursor() port_list = [xxxx] print port_list data_size_list = get_blog_size(cursor,port_list) draw(data_size_list) cursor.close() conn.close() if __name__ == '__main__': main()

    输出结果:

  • 相关阅读:
    javaweb学习总结(三十三)——使用JDBC对数据库进行CRUD
    javaweb学习总结(三十二)——JDBC学习入门
    javaweb学习总结(三十一)——国际化(i18n)
    javaweb学习总结(三十)——EL函数库
    javaweb学习总结(二十九)——EL表达式
    javaweb学习总结(二十八)——JSTL标签库之核心标签
    javaweb学习总结(二十七)——jsp简单标签开发案例和打包
    JSP页面中使用JSTL标签出现无法解析问题解决办法
    MySQL客户端输出窗口显示中文乱码问题解决办法
    windows操作系统查看占用端口的进程
  • 原文地址:https://www.cnblogs.com/gsblog/p/3427266.html
Copyright © 2020-2023  润新知