pandas Matplotlib:: 不显示所有 x 轴数据框变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32572419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Matplotlib:: Not Showing all x-axis data frame variable
提问by Sanjay Mishra
I have a data frame with head as:
我有一个头部的数据框:
m_srcaddr total_fwd_size total_rev_size
0 10.19.139.141 2479.335 175.000
1 10.19.139.143 888.141 92.442
2 10.19.139.144 1044.360 214.592
3 10.19.139.145 7.205 3.274
4 10.19.139.146 2756.958 294.006
.....
I am trying to plot m_srcaddr as x-axis and other 2 columns as y axis.
我试图将 m_srcaddr 绘制为 x 轴,将其他 2 列绘制为 y 轴。
df.plot(x = 'm_srcaddr')
plt.xticks(rotation=90) #import matplotlib.pyplot as plt
plot is showing x axis (m_srcaddr) as interval of 5 like
绘图将 x 轴(m_srcaddr)显示为 5 的间隔,例如
10.19.139.141, 10.19.139.147, 10.19.139.152 ...
I am trying to use the xticks to show all x-axis data but its failing as m_srcaddr not integer.
我正在尝试使用 xticks 来显示所有 x 轴数据,但由于 m_srcaddr 不是整数而失败。
回答by askewchan
Just change your xtickscall to:
只需将您的xticks电话更改为:
plt.xticks(df.index, df['m_srcaddr'], rotation=90)
The first argument gives the locations to put the ticks (df.indexhere is equivalent to np.arange(len(df)), but if your index isn't evenly spaced use the arange). The second argument gives the tick labels.
第一个参数给出放置刻度的位置(df.index这里相当于np.arange(len(df)),但如果您的索引不是均匀分布的,请使用 arange)。第二个参数给出刻度标签。
matplotlib.pyplot.xticks(*args, **kwargs)
matplotlib.pyplot.xticks(*args, **kwargs)
Get or set the x-limits of the current tick locations and labels.
# return locs, labels where locs is an array of tick locations and # labels is an array of tick labels. locs, labels = xticks() # set the locations of the xticks xticks( arange(6) ) # set the locations and labels of the xticks xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )The keyword args, if any, are Textproperties. For example, to rotate long labels:
xticks( arange(12), calendar.month_name[1:13], rotation=17 )
获取或设置当前刻度位置和标签的 x 限制。
# return locs, labels where locs is an array of tick locations and # labels is an array of tick labels. locs, labels = xticks() # set the locations of the xticks xticks( arange(6) ) # set the locations and labels of the xticks xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )关键字 args(如果有)是Text属性。例如,要旋转长标签:
xticks( arange(12), calendar.month_name[1:13], rotation=17 )

