[英]Python - Barchart in Matplotlib - How to change X axis
simple, probably dummy question, but I can't find the answer: 一个简单的,可能是虚拟的问题,但我找不到答案:
How to adjust the X axis for a bar plot in Matplotlib? 如何在Matplotlib中调整条形图的X轴?
my code so far: 到目前为止我的代码:
_ = matplotlib.pyplot.bar(names, value, color="blue")
_.axis([-11,11,0,1])
returns --> AttributeError: 'BarContainer' object has no attribute 'axis'
返回->
AttributeError: 'BarContainer' object has no attribute 'axis'
You can use xlim for this! 您可以为此使用xlim!
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlim.html https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlim.html
Example: 例:
import matplotlib.pyplot as plt
plt.xlim(-11, 11)
First of all a good practise to make things easier is to import this: 首先,使事情变得容易的一个好习惯是导入:
import matplotlib.pyplot as plt
and then you can simply 然后你可以简单地
plt.bar(names, value, color="blue")
plt.xlim([-11,11])
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.