Matplotlib-固定x轴缩放比例和自动缩放y轴 [英] Matplotlib - fixing x axis scale and autoscale y axis

查看:1218
本文介绍了Matplotlib-固定x轴缩放比例和自动缩放y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想绘制数组的一部分,固定x部分,但让y部分自动缩放.我尝试如下所示,但是它不起作用.

I would like to plot only part of the array, fixing x part, but letting y part autoscale. I tried as shown below, but it does not work.

有什么建议吗?

import numpy as np
import matplotlib.pyplot as plt

data=[np.arange(0,101,1),300-0.1*np.arange(0,101,1)]

plt.figure()

plt.scatter(data[0], data[1])
plt.xlim([50,100])
plt.autoscale(enable=True, axis='y')

plt.show()

推荐答案

自动缩放始终使用整个数据范围,因此y轴将按y数据的全部范围进行缩放,而不仅仅是x-范围内的内容限制.

Autoscaling always uses the full range of the data, so the y-axis is scaled by full extent of the y-data, not just what's within the x-limits.

如果您想显示数据的子集,那么仅绘制该子集可能是最简单的:

If you'd like to display a subset of the data, then it's probably easiest to plot only that subset:

import numpy as np
import matplotlib.pyplot as plt

x, y = np.arange(0,101,1) ,300 - 0.1*np.arange(0,101,1)
mask = (x >= 50) & (x <= 100)

fig, ax = plt.subplots()
ax.scatter(x[mask], y[mask])

plt.show()

这篇关于Matplotlib-固定x轴缩放比例和自动缩放y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆