簡體   English   中英

Python-Matplotlib中的Barchart-如何更改X軸

[英]Python - Barchart in Matplotlib - How to change X axis

一個簡單的,可能是虛擬的問題,但我找不到答案:

如何在Matplotlib中調整條形圖的X軸?

到目前為止我的代碼:

_ = matplotlib.pyplot.bar(names, value, color="blue")
_.axis([-11,11,0,1])

返回-> AttributeError: 'BarContainer' object has no attribute 'axis'

您可以為此使用xlim!

https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlim.html

例:

import matplotlib.pyplot as plt
plt.xlim(-11, 11)

首先,使事情變得容易的一個好習慣是導入:

import matplotlib.pyplot as plt

然后你可以簡單地

plt.bar(names, value, color="blue")
plt.xlim([-11,11])

plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM