[英]How to set value gap on Y-axis using Python library matplotlib.pyplot
enter image description here I am trying to plot a bar graph on powerBi using python and i am expecting values on y-axis after the interval of 10 for example 0-10,10-20 upto 100. But in actual it is showing after interval of 25, like 0-25, 26-50 and so on enter image description here我正在尝试使用 python 在 powerBi 上绘制 plot 条形图,我希望在 10 的间隔之后 y 轴上的值例如 0-10,10-20 高达 100。但实际上它显示在间隔之后25 个,例如 0-25、26-50 等等
import matplotlib.pyplot as plt
ax=plt.gca()
#dataset.plot(kind='bar',x='Day',y='Feed_Req_to_Standard',ax=ax)
dataset.plot(kind='bar',x='Day',y=['Feed_%Diff_From_Stand','Feed_Req_to_Standard'], color=['red','green'],ax=ax)
plt.ylim(bottom= -100, top= 100)
plt.xlabel('Days')
plt.show()
You can set the tick locations and labels on the y axis using the function matplotlib.axes.Axes.set_yticks()
.您可以使用 function matplotlib.axes.Axes.set_yticks()
在 y 轴上设置刻度位置和标签。 If you want to take a closer look, here is the documentation .如果你想仔细看看, 这里是文档。 Applied to your problem, it would probably be applied like this (note I haven't tested it though as I don't have access to your data).适用于您的问题,它可能会像这样应用(注意我没有测试它,因为我无权访问您的数据)。
import matplotlib.pyplot as plt
from matplotlib.axes import Axes
spacing = 10
ticks = [spacing*i for i in range(5)] # gets ticks values
Axes.set_yticks(ticks)
ax=plt.gca()
dataset.plot(kind='bar',x='Day',y=['Feed_%Diff_From_Stand','Feed_Req_to_Standard'], color=['red','green'],ax=ax)
plt.ylim(bottom= -100, top= 100)
plt.xlabel('Days')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.