import pandas as pd import matplotlib.pyplot as plt
df = pd.read_excel('london2018.xlsx') print(df)
df.plot(x='Month', y='Tmax') plt.show()
""" 上面的图就是折线图,折线图语法有三种 df.plot(x='Month', y='Tmax') df.plot(x='Month', y='Tmax', kind='line') df.plot.line(x='Month', y='Tmax') """
df.plot(x='Month', y='Tmax', kind='line', grid='True') plt.show()
df.plot(x='Month', y=['Tmax', 'Tmin']) plt.show()
df.plot(x='Month', y='Rain', kind='bar')
plt.show()
df.plot(x='Month', y='Rain', kind='barh') plt.show()
df.plot(x='Month', y=['Tmax', 'Tmin'], kind='bar') plt.show()
df.plot(kind='scatter', x='Month', y='Sun') plt.show()
df.plot(kind='pie', y='Sun') plt.show() """ 上面的饼图绘制有两个小问题: legend图例不应该显示 月份的显示用数字不太正规 """ df.index = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] df.plot(kind='pie', y='Sun', legend=False) plt.show()
df2 = pd.read_csv('londonweather.csv') print(df.head())
print(df2.Rain.describe())
df2.plot.box(y='Rain')
plt.show()
df2.plot(y='Rain', kind='hist')
plt.show()
df2.plot(y='Rain', kind='hist', bins=[0, 25, 50, 75, 100, 125, 150, 175, 200])
plt.show()
df.plot(kind='line', y=['Tmax', 'Tmin', 'Rain', 'Sun'], subplots=True, layout=(2, 2), figsize=(20, 10)) plt.show()
df.plot(kind='bar', y=['Tmax', 'Tmin', 'Rain', 'Sun'], subplots=True, layout=(2, 2), figsize=(20, 10)) plt.show()
df.plot(kind='bar', y=['Tmax', 'Tmin'], subplots=True, layout=(1, 2), figsize=(20, 5), title='The Weather of London') plt.show()
df.plot(kind='pie', y='Rain', legend=False, figsize=(10, 5), title='Pie of Weather inLondon') plt.savefig('pie.png') plt.show()
""" df.plot更多参数 df.plot(x, y, kind, figsize, title, grid, legend, style) - x 只有dataframe对象时,x可用。横坐标 - y 同上,纵坐标变量 - kind 可视化图的种类,如line,hist, bar, barh, pie, kde, scatter - figsize 画布尺寸 - title 标题 - grid 是否显示格子线条 - legend 是否显示图例 - style 图的风格 """
|