简体   繁体   English

如何使用 Python 库 matplotlib.pyplot 在 Y 轴上设置值差距

[英]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()

enter image description here在此处输入图像描述

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.

相关问题 更改y轴的数量计数(Python,matplotlib.pyplot) - Changing the count of numbers of the y-axis (Python, matplotlib.pyplot) Matplotlib.pyplot:如何为现有绘图设置第二个y轴 - Matplotlib.pyplot: How to set up a second y-axis for an existing plot 使用正确的标签将值从 x 轴切换到 y 轴(Python Matplotlib.pyplot 或 Seaborn) - Switch the values from x-axis to y-axis while using the correct labels(Python Matplotlib.pyplot OR Seaborn) 如何在 matplotlib.pyplot 中设置 X 和 Y 轴标题 - How to set X and Y axis Title in matplotlib.pyplot 如何使用 matplotlib.pyplot 在 x 轴上创建分组条形图(按月和年)并在 y 轴上创建值? - How to create a grouped bar chart (by month and year) on the x-axis and values on the y-axis using matplotlib.pyplot? 为什么当我使用matplotlib.pyplot时,y轴下方的数字更大? - why greater number is below on y-axis when I using matplotlib.pyplot? 如何让 matplotlib.pyplot 沿 Y 轴标记每隔几个标签? - How do I get matplotlib.pyplot to label every few labels down the Y-Axis? 如何使用 matplotlib.pyplot 在顶部 y 轴的高点以下设置低点 - How to set low at below high at top y axis with matplotlib.pyplot 在matplotlib.pyplot中使用虚线标记y值 - Marking y value using dotted line in matplotlib.pyplot Python:使用 matplotlib.pyplot 的奇怪 x 轴限制 - Python: Strange x axis limits using matplotlib.pyplot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM