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();

Original: https://www.cnblogs.com/canyangfeixue/p/15401814.html
Author: 残阳飞雪
Title: python Sqlserver数据库画双轴图

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6638/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总