dataframe plot

2020-11-29  本文已影响0人  hehehehe

节点名称,平均报表量,最大报表量
人工识别检查套餐,22.83,90
人工构建检查套餐,44.83,542
制图后处理检查,30.256,670

画图步骤

1)首先定义画图的画布:fig = plt.figure( )
2)然后定义子图ax ,使用 ax= fig.add_subplot( 行,列,位置标)
3)用 ax.plot( )函数或者 df.plot(ax = ax)
4)结尾加plt.show()

1、

plt.subplot(2,1,1)
plt.plot(x, y)

2、

fig, (ax0, ax1) = plt.subplots(nrows=2,ncols=1, figsize=(4,4) , sharex=False)
ax0.plot(x, y)

3、

fig = plt.figure()
ax0 = fig.add_subplot(2,1,1)
ax0.plot(x, y)

import numpy as np 
import matplotlib.pyplot as plt 
x = np.linspace(0, 2 * np.pi, 100) 
y = 2 * np.sin(x)
######################### 
plt.subplot(2,1,1) # subplot(nrows, ncols, plot_number) 
plt.plot(x, y) 
plt.title('normal spines') 
plt.subplot(2,1,2) 
plt.plot(x, y, 'r--') 
plt.title('bottom-left spines') 
# Tweak spacing between subplots to prevent labels from overlapping 
plt.subplots_adjust(hspace=0.5) 
plt.show() 
######################### 
# Create a figure with a set of subplots 
fig, (ax0, ax1) = plt.subplots(nrows=2,ncols=1, figsize=(4,4) , sharex=False)
ax0.plot(x, y) 
ax0.set_title('normal spines') 
ax1.plot(x, y, 'r--') 
ax1.set_title('bottom-left spines') 
plt.show() 
######################### 
fig = plt.figure() 
ax0 = fig.add_subplot(2,1,1) 
ax0.plot(x, y) 
ax0.set_title('normal spines') 
ax1 = fig.add_subplot(2,1,2) 
ax1.plot(x, y, 'r--') 
ax1.set_title('bottom-left spines') 
#plt.show() 
fig.savefig('test.jpg') 
#########################
image.png
from pylab import mpl
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
font=matplotlib.font_manager.FontProperties(fname=r"C:\Windows\Fonts\Deng.ttf")
 
mpl.rcParams['font.sans-serif'] = ['SimHei']

mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] # 指定默认字体:解决plot不能显示中文问题

mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题

df = pd.read_csv("addata2.csv")
print(df)
ax = df.plot(kind = 'bar',x='节点名称',y=['平均报表量','最大报表量'],rot=0,
 title='制图各节点报表统计', grid=True)
ax.set_xlabel('制图检查节点名称')
ax.set_ylabel('报表数量')
# ax = plt.gca()
# ax.grid(True)
# plt.title('制图报表统计',fontproperties=font)
# plt.xlabel('姓名',fontproperties=font)
# plt.ylabel('',fontproperties=font)
# plt.legend(df.columns,loc=1)
#plt.title('制图报表统计')
#plt.xticks()
# plt.yticks([y for y in range(0,180,10)])
for i in range(0,3):
    plt.text(i-0.12,df.get("平均报表量")[i],'%.0f'%df.get("平均报表量")[i], ha='center', va='bottom')
    plt.text(i+0.12,df.get("最大报表量")[i],'%.0f'%df.get("最大报表量")[i], ha='center', va='bottom')
plt.show()
上一篇下一篇

猜你喜欢

热点阅读