Matplotlib自动缩放 [英] Matplotlib autoscale

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

问题描述

我需要获取一张使用matplotlib自动拟合数据的图.这是我得到的代码:

I need to get a plot that fits the data automatically using matplotlib. This is the code I was given:

import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
....
lines = LineCollection(mpl.line_holder, colors=mpl.colorholder , linestyle='solid')
plt.axes().add_collection(lines)
plt.axes().set_aspect('equal', 'datalim')
plt.draw()
plt.show()

这将创建一个绘图,但是无论数据是什么,窗口都始终是相同的(0-〜.8),即使所有数据都在该窗口之外.生成的窗口无法放大,只能放大,因此这是一个主要问题.我找不到在任何地方设置任何类型的大小设置的地方,II也找不到关于默认值的详细信息.我需要一个窗口来自动拟合数据,但是我找不到能做到这一点的任何函数(由于某种原因,autoscale_on(True)不能做到这一点).数据是高度可变的,因此不能设置硬限制.我该如何使其正确显示?

This creates a plot, however the window is always the same (0-~.8) no matter what the data is, even if all of the data is outside that window. The resulting window has no ability to zoom out, only in, so this is a major problem. I can't find anywhere where any kind of sizing is set, nor can II find details on what defaults are. I need the window to automatically fit the data, but I can't find any function that does it (for some reason, autoscale_on(True) doesn't do it). The data is highly variable, so setting hard limits is not an option. How can i get this to display properly?

推荐答案

不确定这是否是您想要的,但是如果这不是您想要的,我可以更改它.

Not sure if this what you wanted, but I can change it if this was not what you were looking for.

import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection

import pylab as p

fig = plt.figure()
pts1 = []
pts2 = []
for i in range(100):
    pts1.append([i,i])
    pts2.append([-i-3,-i])
lines = LineCollection([pts1,pts2], linestyles='solid')
subplt = fig.add_subplot(111,aspect='equal')
subplt.add_collection(lines)
subplt.autoscale_view(True,True,True)
p.show()

希望有帮助.

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

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