## Re: [Matplotlib-users] Set x axis length of all subplots to same width on screen

 Re: [Matplotlib-users] Set x axis length of all subplots to same width on screen From: Tony Yu - 2012-04-26 17:02:31 Attachments: Message as HTML On Thu, Apr 26, 2012 at 12:51 PM, willfurnass wrote: > > I've converted a simple MATLAB script [1] for wavelet decomposition-based > analysis to Python. I now want to create figures similar to [2] that > feature five subplots in one column, with the 1st and 3rd being generated > using 'subplot.plot' and the others being generated using 'subplot.imshow'. > > I want to find a way of scaling the x and y axes of all subplots so that > they're the same size on screen across all subplots. Unfortunately I can't > find any combination of 'aspect' or 'extent' that will let me do this. I > should note that I've added colorbars to all my image plots; the problem > exists regardless of whether these are used. > > Has anyone got any suggestions? Apologies if this is a trivial matter; I'm > fairly new to MP. > > FYI I'm using matplotlib v1.1.0. > > [1] > > http://www.mathworks.com/matlabcentral/fileexchange/18409-comparing-time-series-using-semblance-analysis > [2] http://www.mathworks.com/matlabcentral/fx_files/18409/1/goldoil.jpg > > Regards, > > Will Furnass > > You could try fig, axes = plt.subplots(nrows=5, sharex=True, sharey=True) And then call `axes[0].plot(...)` and `axes[1].imshow(...)`. You could also unpack the axes array and access them that way (if you prefer): ax0, ax1, ax2, ax3, ax4 = axes ax0.plot(...) Best, -Tony

 [Matplotlib-users] Set x axis length of all subplots to same width on screen From: willfurnass - 2012-04-26 16:51:20 I've converted a simple MATLAB script [1] for wavelet decomposition-based analysis to Python. I now want to create figures similar to [2] that feature five subplots in one column, with the 1st and 3rd being generated using 'subplot.plot' and the others being generated using 'subplot.imshow'. I want to find a way of scaling the x and y axes of all subplots so that they're the same size on screen across all subplots. Unfortunately I can't find any combination of 'aspect' or 'extent' that will let me do this. I should note that I've added colorbars to all my image plots; the problem exists regardless of whether these are used. Has anyone got any suggestions? Apologies if this is a trivial matter; I'm fairly new to MP. FYI I'm using matplotlib v1.1.0. [1] http://www.mathworks.com/matlabcentral/fileexchange/18409-comparing-time-series-using-semblance-analysis [2] http://www.mathworks.com/matlabcentral/fx_files/18409/1/goldoil.jpg Regards, Will Furnass -- View this message in context: http://old.nabble.com/Set-x-axis-length-of-all-subplots-to-same-width-on-screen-tp33753799p33753799.html Sent from the matplotlib - users mailing list archive at Nabble.com.
 Re: [Matplotlib-users] Set x axis length of all subplots to same width on screen From: Tony Yu - 2012-04-26 17:02:31 Attachments: Message as HTML On Thu, Apr 26, 2012 at 12:51 PM, willfurnass wrote: > > I've converted a simple MATLAB script [1] for wavelet decomposition-based > analysis to Python. I now want to create figures similar to [2] that > feature five subplots in one column, with the 1st and 3rd being generated > using 'subplot.plot' and the others being generated using 'subplot.imshow'. > > I want to find a way of scaling the x and y axes of all subplots so that > they're the same size on screen across all subplots. Unfortunately I can't > find any combination of 'aspect' or 'extent' that will let me do this. I > should note that I've added colorbars to all my image plots; the problem > exists regardless of whether these are used. > > Has anyone got any suggestions? Apologies if this is a trivial matter; I'm > fairly new to MP. > > FYI I'm using matplotlib v1.1.0. > > [1] > > http://www.mathworks.com/matlabcentral/fileexchange/18409-comparing-time-series-using-semblance-analysis > [2] http://www.mathworks.com/matlabcentral/fx_files/18409/1/goldoil.jpg > > Regards, > > Will Furnass > > You could try fig, axes = plt.subplots(nrows=5, sharex=True, sharey=True) And then call `axes[0].plot(...)` and `axes[1].imshow(...)`. You could also unpack the axes array and access them that way (if you prefer): ax0, ax1, ax2, ax3, ax4 = axes ax0.plot(...) Best, -Tony
 Re: [Matplotlib-users] Set x axis length of all subplots to same width on screen From: willfurnass - 2012-04-27 17:56:31 On Thu, Apr 26, 2012 at 12:51 PM, willfurnass wrote: > > I've converted a simple MATLAB script [1] for wavelet decomposition-based > analysis to Python. I now want to create figures similar to [2] that > feature five subplots in one column, with the 1st and 3rd being generated > using 'subplot.plot' and the others being generated using > 'subplot.imshow'. > > I want to find a way of scaling the x and y axes of all subplots so that > they're the same size on screen across all subplots. Unfortunately I > can't > find any combination of 'aspect' or 'extent' that will let me do this. I > should note that I've added colorbars to all my image plots; the problem > exists regardless of whether these are used. > > [1] > > http://www.mathworks.com/matlabcentral/fileexchange/18409-comparing-time-series-using-semblance-analysis > [2] http://www.mathworks.com/matlabcentral/fx_files/18409/1/goldoil.jpg You could try fig, axes = plt.subplots(nrows=5, sharex=True, sharey=True) And then call `axes[0].plot(...)` and `axes[1].imshow(...)`. You could also unpack the axes array and access them that way (if you prefer): ax0, ax1, ax2, ax3, ax4 = axes ax0.plot(...) ---- Hi Tony and others, Thanks for the suggestion Tony. It works if I remove my colour bars. However if the colour bars are enabled (for the images on the 2nd, 4th and 5th rows) then the image on the 5th and last row is squashed up on the LHS of the subplot area to make room for all 3 (!) colour bars, even though all subplots should share an x axis. Any further suggestions? Also, I'm still having problems getting tick labels on ax.plot() and ax.imshow() subplots to line up: I create one subplot using plot(t_vec, y_vec) I then create an image using t_vec and y_vec and display it as a second subplot using imshow(image); the width of the image matrix is len(t_vec) (not t_vec.max()) I am looking for a sane way of displaying the two subplots above each other so that they are both the same width in pixels and have x tick labels at consistent intervals (in pixels) that correspond to multiples of some value of t. I have tried using ax.xaxis.set_major_formatter(ticker.FuncFormatter(xformat)) to scale the image subplot ticks but can't get this to work in conjunction with the setting of the tick intervals on both subplot axes using set_xticks. Has anyone got any suggestions? Regards, Will -- View this message in context: http://old.nabble.com/Set-x-axis-length-of-all-subplots-to-same-width-on-screen-tp33753799p33760459.html Sent from the matplotlib - users mailing list archive at Nabble.com.
 Re: [Matplotlib-users] Set x axis length of all subplots to same width on screen From: willfurnass - 2012-04-27 17:57:39 On Thu, Apr 26, 2012 at 12:51 PM, willfurnass wrote: > > I've converted a simple MATLAB script [1] for wavelet decomposition-based > analysis to Python. I now want to create figures similar to [2] that > feature five subplots in one column, with the 1st and 3rd being generated > using 'subplot.plot' and the others being generated using > 'subplot.imshow'. > > I want to find a way of scaling the x and y axes of all subplots so that > they're the same size on screen across all subplots. Unfortunately I > can't > find any combination of 'aspect' or 'extent' that will let me do this. I > should note that I've added colorbars to all my image plots; the problem > exists regardless of whether these are used. > > [1] > > http://www.mathworks.com/matlabcentral/fileexchange/18409-comparing-time-series-using-semblance-analysis > [2] http://www.mathworks.com/matlabcentral/fx_files/18409/1/goldoil.jpg You could try fig, axes = plt.subplots(nrows=5, sharex=True, sharey=True) And then call `axes[0].plot(...)` and `axes[1].imshow(...)`. You could also unpack the axes array and access them that way (if you prefer): ax0, ax1, ax2, ax3, ax4 = axes ax0.plot(...) ---- Hi Tony and others, Thanks for the suggestion Tony. It works if I remove my colour bars. However if the colour bars are enabled (for the images on the 2nd, 4th and 5th rows) then the image on the 5th and last row is squashed up on the LHS of the subplot area to make room for all 3 (!) colour bars, even though all subplots should share an x axis. Any further suggestions? Also, I'm still having problems getting tick labels on ax.plot() and ax.imshow() subplots to line up: I create one subplot using plot(t_vec, y_vec) I then create an image using t_vec and y_vec and display it as a second subplot using imshow(image); the width of the image matrix is len(t_vec) (not t_vec.max()) I am looking for a sane way of displaying the two subplots above each other so that they are both the same width in pixels and have x tick labels at consistent intervals (in pixels) that correspond to multiples of some value of t. I have tried using ax.xaxis.set_major_formatter(ticker.FuncFormatter(xformat)) to scale the image subplot ticks but can't get this to work in conjunction with the setting of the tick intervals on both subplot axes using set_xticks. Has anyone got any suggestions? Regards, Will -- View this message in context: http://old.nabble.com/Set-x-axis-length-of-all-subplots-to-same-width-on-screen-tp33753799p33760460.html Sent from the matplotlib - users mailing list archive at Nabble.com.