好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python 图表

#图表

import matplotlib.pyplot as plt

fig,ax=plt.subplots(2,2) ax[0,1].plot(x,y,‘r--*‘,label=‘sin‘) ax[0,1].legend(loc=‘upper right‘) ax[0,1].grid() fig.savefig(‘fig.png‘)

 

import pandas as pd

df=pd.read_csv(‘./data/data2.csv‘,index_col=‘产品编码‘,encoding=‘gbk‘) df.head()

y=df[‘供应商进货价‘].values

x=df.index.values

#创建折线图 from pylab import mpl mpl.rcParams[‘font.sans-serif‘]=[‘simhei‘] fig,ax=plt.subplots() ax.plot(x,y,‘r‘) ax.set(title=‘年度price趋势图‘,xlabel=‘年度‘,ylabel=‘价格‘) # plt.title(‘年度price趋势图‘) plt.show()

#创建柱线图 from pylab import mpl mpl.rcParams[‘font.sans-serif‘]=[‘simhei‘] fig,ax=plt.subplots() ax.bar(x,y,0.5,color=‘green‘) ax.set(title=‘年度price趋势图‘,xlabel=‘年度‘,ylabel=‘价格‘) # plt.title(‘年度price趋势图‘) plt.show()

#水平柱形图

from pylab import mplmpl.rcParams[‘font.sans-serif‘]=[‘simhei‘]fig,ax=plt.subplots()ax.barh(x,y,0.5,color=‘green‘)ax.set(title=‘年度price趋势图‘,xlabel=‘年度‘,ylabel=‘价格‘)# plt.title(‘年度price趋势图‘)plt.show()

查看更多关于python 图表的详细内容...

  阅读:25次