import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
def bar():
df=pd.DataFrame({'HEIGHT':[175,165,162,158,180],'AGE':[23,30,27,21,35],'SCORE':[80,100,70,85,65]},
columns=['HEIGHT','AGE','SCORE'],
index=['jack','leo','james','Lily','David'])
df_plot=df.plot(kind='bar',rot=0) # rot 横坐标值旋转角度
df_plot.legend(df.columns,loc=2) #columns 列名图标摆放位置
df_plot.set_yticks([x for x in range(1,180,10)]) # Y轴刻度值
df_plot.set_ylabel('Longdian')
df_plot.grid(alpha=0.4)
plt.savefig('test1.jpg')
plt.show()
def weather():
df=pd.DataFrame({'2018-8':[30,29,34,23,45,12,23,34,36,37,38,39,30,23,25,27,28,33,34,36,21,24,26,46,30,36,56,23,35,32],
'2018-6':[20,39,24,13,15,12,13,24,26,47,18,19,10,13,15,17,18,31,32,33,11,23,46,36,20,26,16,13,15,12],
'2018-7':[31,29,32,23,45,13,23,34,26,27,28,29,20,33,25,37,38,23,24,26,21,24,36,36,20,26,36,33,25,32]})
ax=df.plot(kind='line',marker='v',rot=0,ylim=[10,60])
date_range=pd.date_range('8/1/2018','8/31/2018',freq='d')
ax.set_xticks(date_range.day)
plt.savefig('test2.jpg')
plt.show()
def simple():
plt.plot([1,2,3],label='test')
plt.xlabel('X')
plt.ylabel('Y')
plt.savefig('test3.jpg')
plt.show()
def plot():
df=pd.DataFrame(np.random.randn(1000,4),columns=['a','b','c','d'])
df=df.cumsum()
df.plot(alpha=0.7,linewidth=1.5)
plt.savefig('test5.jpg')
plt.show()
def dian():
df=pd.DataFrame(np.random.rand(100,4),columns=list('ABCD'))
df.plot.scatter('A','B',df['C']*200)
plt.savefig('test4.jpg')
plt.show()
if __name__=='__main__':
bar()
weather()
simple()
plot()
dian()
import numpy as np
import matplotlib.pyplot as plt
def bar():
df=pd.DataFrame({'HEIGHT':[175,165,162,158,180],'AGE':[23,30,27,21,35],'SCORE':[80,100,70,85,65]},
columns=['HEIGHT','AGE','SCORE'],
index=['jack','leo','james','Lily','David'])
df_plot=df.plot(kind='bar',rot=0) # rot 横坐标值旋转角度
df_plot.legend(df.columns,loc=2) #columns 列名图标摆放位置
df_plot.set_yticks([x for x in range(1,180,10)]) # Y轴刻度值
df_plot.set_ylabel('Longdian')
df_plot.grid(alpha=0.4)
plt.savefig('test1.jpg')
plt.show()
def weather():
df=pd.DataFrame({'2018-8':[30,29,34,23,45,12,23,34,36,37,38,39,30,23,25,27,28,33,34,36,21,24,26,46,30,36,56,23,35,32],
'2018-6':[20,39,24,13,15,12,13,24,26,47,18,19,10,13,15,17,18,31,32,33,11,23,46,36,20,26,16,13,15,12],
'2018-7':[31,29,32,23,45,13,23,34,26,27,28,29,20,33,25,37,38,23,24,26,21,24,36,36,20,26,36,33,25,32]})
ax=df.plot(kind='line',marker='v',rot=0,ylim=[10,60])
date_range=pd.date_range('8/1/2018','8/31/2018',freq='d')
ax.set_xticks(date_range.day)
plt.savefig('test2.jpg')
plt.show()
def simple():
plt.plot([1,2,3],label='test')
plt.xlabel('X')
plt.ylabel('Y')
plt.savefig('test3.jpg')
plt.show()
def plot():
df=pd.DataFrame(np.random.randn(1000,4),columns=['a','b','c','d'])
df=df.cumsum()
df.plot(alpha=0.7,linewidth=1.5)
plt.savefig('test5.jpg')
plt.show()
def dian():
df=pd.DataFrame(np.random.rand(100,4),columns=list('ABCD'))
df.plot.scatter('A','B',df['C']*200)
plt.savefig('test4.jpg')
plt.show()
if __name__=='__main__':
bar()
weather()
simple()
plot()
dian()