使用python的pylab创建可滚动的多图 [英] Creating a scrollable multiplot with python's pylab

查看:76
本文介绍了使用python的pylab创建可滚动的多图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多图,并希望使用python在同一图中绘制它们. 我目前正在使用pylab作图,但由于绘制的太多,因此它们只能在另一个之上绘制. 有没有一种方法可以使图形可滚动,从而使图形足够大并且可以通过使用滚动条看到?

I have a large amount of plots and wish to draw them in the same figure using python. I'm currently using pylab for the plots, but since there are too many they are drawn one on top of the other. Is there a way to make the figure scrollable, such that graphs are large enough and still visible by using scrollbar?

我可以为此使用PyQT,但是我可能缺少pylab的Figure对象的功能...

I can use PyQT for this, but there might be a feature of pylab's figure object that I'm missing...

推荐答案

这符合您想要的内容,即使不是字母也是如此.我认为您想要一个具有多个axes的窗口,然后能够在各个轴之间滚动(但仍然只能一次平均看到一个轴),该解决方案只有一个轴,并且可以通过一个滑块来选择数据集进行绘制.

This matches the spirit of what you want, if not the letter. I think you want a window with a number of axes and then be able to scroll through the axes (but still only be able to see on average one at a time), the solution has a single axes and a slider that selects which data set to plot.

import numpy
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
# fake data
xdata = numpy.random.rand(100,100) 
ydata = numpy.random.rand(100,100) 
# set up figure
fig = plt.figure()
ax = fig.add_subplot(111)
ax.autoscale(True)
plt.subplots_adjust(left=0.25, bottom=0.25)

# plot first data set
frame = 0
ln, = ax.plot(xdata[frame],ydata[frame])

# make the slider
axframe = plt.axes([0.25, 0.1, 0.65, 0.03])
sframe = Slider(axframe, 'Frame', 0, 99, valinit=0,valfmt='%d')

# call back function
def update(val):
    frame = numpy.floor(sframe.val)
    ln.set_xdata(xdata[frame])
    ln.set_ydata((frame+1)* ydata[frame])
    ax.set_title(frame)
    ax.relim()
    ax.autoscale_view()
    plt.draw()

# connect callback to slider   
sframe.on_changed(update)
plt.show()

这是根据此问题中的代码改编而成的.您可以使用按钮小部件( doc )添加下一个/后退按钮.

This is adapted from the code in this question. You can add next/back buttons using the button widgets (doc).

这篇关于使用python的pylab创建可滚动的多图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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