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?
I can use PyQT for this, but there might be a feature of pylab's figure object that I'm missing...
Grid Plots Next, we'll try to plot some graphs as a grid, that is, multiplots with multiple columns. Here, we will create a multiplot with 4 plots, we will make it a 2×2 grid, which means nrows=2 and ncols=2, with each image being identified by the index again, in a row-major order.
Pylab is a module that provides a Matlab like namespace by importing functions from the modules Numpy and Matplotlib. Numpy provides efficient numerical vector calculations based on underlying Fortran and C binary libraries. Matplotlib contains functions to create visualizations of data.
To create multiple plots use matplotlib. pyplot. subplots method which returns the figure along with Axes object or array of Axes object. nrows, ncols attributes of subplots() method determine the number of rows and columns of the subplot grid.
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 = int(round(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()
This is adapted from the code in this question. You can add next/back buttons using the button widgets (doc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With