import matplotlib.pyplot as plt
import random
%matplotlib inline
%config InlineBackend.figure_format = 'svg'
plt.rcParams["font.sans-serif"] = 'SimHei'
import pandas as pd
df=pd.read_csv('全国房价排行表.txt',usecols=['城市','单价'],nrows=10)
help(df.plot)
yticks=(0,10000,20000,30000,40000,50000,60000,70000)
df.plot(kind='bar',xlable='城市',ylabel='单价',yticks=yticks,title='房价前十的城市')
plt.grid(axis='y')
plt.show()
把报错啥的贴一下
没有xlable或ylable这两个参数,换成x和y试试:
df.plot(kind='bar',x='城市',y='单价',yticks=yticks,title='房价前十的城市')
import numpy as np
import matplotlib.pyplot as plt
import random
import pandas as pd
plt.rcParams["font.sans-serif"] = 'SimHei'
df=pd.read_csv('全国房价排行表.txt',header=0,usecols=['城市','单价'],nrows=3)
yticks=(0,10000,20000,30000,40000,50000,60000,70000)
plt.yticks(yticks)
xticks=df['城市'].index
xlabel=df['城市'].values
height=df['单价'].values
plt.bar(xticks,height,width=0.35,tick_label=xlabel)
plt.show()