zoukankan      html  css  js  c++  java
  • python Sqlserver数据库画双轴图

    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd  # data processing, CSV file I/O (e.g. pd.read_csv)
    import pymssql  # 引入pymssql模块
    import seaborn as sns  # Provides a high level interface for drawing attractive and informative statistical graphics
    from matplotlib.font_manager import FontProperties
    from pylab import *
    import matplotlib.pyplot as plt
    import seaborn as sns
    plt.rcParams['font.sans-serif']=['SimHei']#用来正常显示中文标签
    plt.rcParams['axes.unicode_minus']=False#用来正常显示负号
    
    if __name__ == '__main__':
     conn = pymssql.connect(host='localhost', user='wonderful', password='wonderful', database='ProcreateV93',
                            charset='GBK')
    sql="select left(convert(char, op.MadeDate, 12), 4) as months, "
    "COUNT(DISTINCT OP.O_iD)                 AS patientcount, "
    "sum(op.OPSTimes)                           optime, "
    "(COUNT(DISTINCT OP.O_iD)+0.0)/(sum(op.OPSTimes)+0.0) as pct "
    "from Oplan op "
    "where op.GroupName is not null "
    "and UserName is not null "
    "group by left(convert(char, op.MadeDate, 12), 4)"
    
    df0 = pd.read_sql(sql, conn)
    df = pd.DataFrame(df0)
    print(df)
    fig, ax1 = plt.subplots()
    plt.xticks(rotation=45)
    ax1.bar(df.months.values,df.patientcount.values, color="black", alpha=0.5, label="患者数")
    ax1.set_xlabel("患者人数")
    ax1.set_ylabel("患者数据")
    ax2 = ax1.twinx()
    ax2.plot(df.months.values, df.pct.values, color="green", label="周期数")
    ax2.set_ylabel("周期数")
    fig.legend(loc="upper right", bbox_to_anchor=(1, 1), bbox_transform=ax1.transAxes)
    plt.show();

  • 相关阅读:
    python os.stat() 和 stat模块详解
    Python中datetime库的用法
    js中Array的map()函数,其中的回调函数还能这么用
    通常用于返回值的三目运算符
    浏览器渲染页面的时候,不同的script块之间的关系
    模板字面量
    let和const
    js 数组 map方法
    一些常用的js循环,如for
    session
  • 原文地址:https://www.cnblogs.com/canyangfeixue/p/15401814.html
Copyright © 2011-2022 走看看