简体   繁体   中英

Changing canvas size dynamically

I want to plot multiple time-series (each time-series in its own plot) using the plot() -method of matplotlib.

  • X-Axis: Time
  • Y-Axis: Parameter-Value

As the time-series have different lengths, I want to resize the canvas along the X-Axis dynamically, so that the time-series do not get stretched/compressed dependent on their total length. The size of the whole figure should stay the same, independent of the time-series-length. I know how to modify the figure size using

rcParams['figure.figsize'] = width, height

but I do only want to modify the canvas size (the part of the figure where the time-series is actually plotted in). Is there a similar way of just changing the figure's canvas?

I think you want to change the dimensions of the axes that your time-series is being plotted in, rather than the dimensions of the figure canvas (which as far as I'm aware can't be altered without changing the overall figure size).

You can do this using ax.set_position() , which takes a tuple of (left, bottom, width, height) values in normalized canvas coordinates between 0 and 1.

from pylab import *
nr = 4
nc = 1
fig,axes = subplots(nr,nc,sharex=True)

The sharex keyword tells the subplots to keep their x limits the same. Replace plot in your application with axes[ith index].plot , etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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