简体   繁体   English

如何更改matplotlib中的轴限制?

[英]How to change the limits of axes in matplotlib?

I have plot where the x-axis starts from 0-100. 我有x轴从0-100开始的图。 I want to change it to 10-100. 我想将其更改为10-100。 I would be grateful if someone could give any suggestion. 如果有人可以提出任何建议,我将不胜感激。 Thanks 谢谢

If you just use pyplot for a simple plot, you can try this function : 如果仅将pyplot用于简单绘图,则可以尝试以下功能

import matplotlib.pyplot as plt
...
plt.xlim(10, 100)

If you want to set specific axes , you can try this method : 如果要设置特定的axes ,可以尝试以下方法

import matplotlib.pyplot as plt
...
ax = plt.gca()
ax.set_xlim(10, 100)

From a SO community wiki here 此处的SO社区Wiki

set_xlim() limits the data that is displayed on the plot. set_xlim()限制在绘图上显示的数据。

In order to change the bounds of the axis, use set_xbound() 为了更改轴的边界,请使用set_xbound()

So I'm pretty sure you actually want 所以我很确定你真的想要

ax.set_xbound(lower=10, upper=100)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM