无法更改图表上的刻度频率 [英] Unable to change the tick frequency on my chart

查看:43
本文介绍了无法更改图表上的刻度频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了许多关于更改SO的变动频率的问题,这在构建折线图时确实有所帮助,但是在制作条形图时我一直在努力.所以下面是我的代码

I have seen many questions on changing the tick frequency on SO, and that did help when I am building a line chart, but I have been struggling when its a bar chart. So below are my codes

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

df = pd.DataFrame(np.random.randint(1,10,(90,1)),columns=['Values'])
df.plot(kind='bar')
plt.show()

这就是我看到的输出.如何更改滴答频率?

and thats the output I see. How do I change the tick frequency ?

(要在x轴上更清楚地显示5的频率!)

(To be more clearer frequency of 5 on x axis!)

推荐答案

使用 Pandas 绘图功能可以做到:

Using Pandas plot function you can do:

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randint(1,10,(90,1)),columns=['Values'])
df.plot(kind='bar', xticks=np.arange(0,90,5))

或更佳:

df.plot(kind='bar', xticks=list(df.index[0::5]))

这篇关于无法更改图表上的刻度频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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