The y axis of my matplotlib bar chart is between 0 and 1. However, all values for in the chart are between 0.8 and 1 so I would like to start the y axis at 0.7. I haven't been able to find the pandas method of doing this so any help would be appreciated.
Thanks in advance
答案 0 :(得分:2)
@ChrisA在评论中提供了最佳答案:如果使用DataFrame.plot()
方法,请添加参数ylim=(0.7, 1)
如果您使用了常用的import matplotlib.pyplot as plt
,则快速的解决方法是在pandas plot命令下添加以下行:
# gca = "get current axis"
ax = plt.gca()
# ax.get_ylim() returns a tuple of (lower ylim, upper ylim)
ax.set_ylim(0.7, ax.get_ylim()[1])
如果您使用的面向对象的matplotlib API通常以fig, ax = plt.subplots()
(参考:The Lifecycle of a Plot)开头,则无需运行ax = plt.gca()
。 / p>