Matplotlib ::不显示所有x轴数据框变量 [英] Matplotlib:: Not Showing all x-axis data frame variable

查看:452
本文介绍了Matplotlib ::不显示所有x轴数据框变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,其头部为:

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
.....

我正在尝试将m_srcaddr绘制为x轴,并将其他2列绘制为y轴.

I am trying to plot m_srcaddr as x-axis and other 2 columns as y axis.

df.plot(x = 'm_srcaddr')
plt.xticks(rotation=90)   #import matplotlib.pyplot as plt

图显示x轴(m_srcaddr)为5的间隔,如

plot is showing x axis (m_srcaddr) as interval of 5 like

10.19.139.141, 10.19.139.147, 10.19.139.152 ...

我正在尝试使用xticks显示所有x轴数据,但失败的原因是m_srcaddr不是整数.

I am trying to use the xticks to show all x-axis data but its failing as m_srcaddr not integer.

推荐答案

只需更改您的 xticks 呼叫:

Just change your xticks call to:

plt.xticks(df.index, df['m_srcaddr'], rotation=90)

第一个参数给出了放置刻度线的位置(df.index等同于np.arange(len(df)),但是如果索引的间距不均匀,则使用arange).第二个参数给出了刻度标签.

The first argument gives the locations to put the ticks (df.index here 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.

获取或设置当前刻度位置和标签的x限制.

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') )

关键字args(如果有)是文本属性.例如,旋转 长标签:

The keyword args, if any, are Text properties. For example, to rotate long labels:

xticks( arange(12), calendar.month_name[1:13], rotation=17 )

这篇关于Matplotlib ::不显示所有x轴数据框变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆