如何在matplotlib中使用'ax.set_xticklabels'

时间:2018-11-30 14:52:18

标签: python matplotlib

每个人。使用'matplotlib'在条形图中标记x轴时出现问题。我的代码在这里:

import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt


df=pd.read_csv('bikes_October18.csv') #read data from the csv file 


a=df['start_station_name'].value_counts()
statioins_number=a.count()
b=df['end_station_name'].value_counts()
c=b.reindex(a.index)
df1=pd.DataFrame({'stations':a.index})
df1['frequncy_start']=df1.stations.map(a)
df1['frequncy_end']=df1.stations.map(c)
print(df1)

ind = np.arange(len(a))  # the x locations for the groups
width = 0.35  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(ind - width/2, a, width,
                color='Orange', label='Start')
rects2 = ax.bar(ind + width/2, c, width,
                color='Green', label='End')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Frequency')
ax.set_title('Frequency by stations and direction')
ax.set_xticklabels(a.index)
plt.xticks(rotation=90)
ax.legend()
plt.rcParams['figure.figsize']=(25,15)

我得到了这样的东西: enter image description here

但是,我真的想要这样的东西: enter image description here

我找不到错误。有人可以帮忙吗?非常感谢你!

0 个答案:

没有答案