subplot

Matplotlib: enforce equal size (height) of subplots?

别说谁变了你拦得住时间么 提交于 2019-12-07 10:56:54
问题 I have a figure containing three subplots. The first subplot is an image ( imshow ), while the other two are distributions ( plot ). Here's the code: # collects data imgdata = ... # img of shape (800, 1600, 3) x = ... # one 1600-dimensional vector y = ... # one 800-dimensional vector # create the figure f = plt.figure() # create subplots subplot_dim = (1, 3) p_img = plt.subplot2grid(subplot_dim, (0, 0), aspect="auto") p_x = plt.subplot2grid(subplot_dim, (0, 1), aspect="auto") p_y = plt

Matplotlib: subplot

社会主义新天地 提交于 2019-12-06 15:25:06
I have several time series signals (8x8) that I would like to plot using subplot. My data are stored in a matrix called H(x, y, N) where N is the number of points in each signal. I would like to display the 64 signals using subplots. fig = figure(figsize=(12,8)) time = np.arange(0, Nt, 1) for x in range(8): for y in range(8): subplot(8,y+1,x+1) plot(time,H[x,y,:]) What I get is 8 signals in the first row, 4 in the second one, then 2, 2, 1, 1, 1 and 1. That's not how subplot indexing works. From the docs to subplot : subplot(nrows, ncols, plot_number) Where nrows and ncols are used to

Is it possible to automatically generate multiple subplots in matplotlib?

强颜欢笑 提交于 2019-12-06 13:54:43
Is it possible to automatically generate multiple subplots in matplotlib? An example of the process I want to automate is: import matplotlib.pyplot as plt figure = plt.figure() ax1 = figure.add_subplot(2, 3, 1) ax2 = figure.add_subplot(2, 3, 2) ax3 = figure.add_subplot(2, 3, 3) ax4 = figure.add_subplot(2, 3, 4) ax5 = figure.add_subplot(2, 3, 5) ax6 = figure.add_subplot(2, 3, 6) The subplots need unique names, as this will allow me to do stuff like: for ax in [ax1, ax2, ax3, ax4, ax5, ax6]: ax.set_title("example") Many thanks. Addition: Are there any functions that automate the generation of

How to add legend below subplots in matplotlib?

久未见 提交于 2019-12-06 12:10:26
问题 I am trying to add a legend below a 3-column subplot figure. I have tried the following: fig, ax = plt.subplots(ncols=3) ax[0].plot(data1) ax[1].plot(data2) ax[2].plot(data3) ax_sub = plt.subplot(111) box = ax_sub.get_position() ax_sub.set_position([box.x0, box.y0 + box.height * 0.1,box.width, box.height * 0.9]) ax_sub.legend(['A', 'B', 'C'],loc='upper center', bbox_to_anchor=(0.5, -0.3),fancybox=False, shadow=False, ncol=3) plt.show() However, this creates just one empty frame. When I

Error in MATLAB colorbar tick labeling?

こ雲淡風輕ζ 提交于 2019-12-06 07:22:51
I am plotting 9 subplots as shown in figure below with one color bar for three subplots. Here I want to show the highest value in color bar as > value , surprisingly when I manually edit the tick label as h.TickLabels{end} = ['>' h.TickLabels{end}]; the color bar starts repeating the value. When I remove h.TickLabels{end} = ['>' h.TickLabels{end}]; the color bar show no problem. When I change the figure size in set(gcf, 'PaperUnits', 'inches', 'PaperPosition', [0 0 8 8]) as [0 0 5 5] colorbar labeling again changes. How to resolve this error? Below are my working example and output image: data

Matplotlib - Different tick label alignment along the same axis

蓝咒 提交于 2019-12-06 06:21:58
I have a figure with a lot of subplot, such that the last ticklabel of an axis is written over the first tick label of the next one. See example here As I want to keep the spacing between the subplots as I set it, I would like to have a different alignment depending on the tick, as it could be produced by : plt.xticks([0], ha = 'left') plt.xticks([0.2,0.4], ha = 'center') plt.xticks([0.6], ha = 'right') Using that, only the last call of xticks is shown on the figure. In another way, the idea is to align first and last tick labels such that they stay within the subplot. Hope I'm clear ! Any

How to create space between subplots?

让人想犯罪 __ 提交于 2019-12-06 05:54:25
问题 The title pretty much says it all. I have a notebook containing two subplots and would like to create some space between them. They look too close to one another per say. 回答1: With matplotlib.Figure.subplots_adjust: import matplotlib.pyplot as plt fig, (ax1, ax2) = plt.subplots(1, 2) ax1.plot([1,2,3], [1,2,3]) ax2.plot([1,2,3], [3,2,1]) plt.show() increasing the width can be done with the wspace parameter: ... # same setup as before fig.subplots_adjust(wspace=2) plt.show() If you want to have

setting the axis min and max values to stick

我是研究僧i 提交于 2019-12-06 03:10:56
I have a (3,4) subplot each showing scatterplots. The ranges of the scatterplots vary so some of my plots have axes x(0-30) and y(0-8), but some have x(18-22) and y(4-7). I have set my xlim to [0 30], and ylim to [0 8] but that sets my axes to never go lower than 0, higher than 30 etc. How do I set my axis to "stick" at (0,0) for the origin of each plot, and "stick" at 8 for Y and 30 for X. TIA for any help update per comment on answer: Still having the same issue with below code %% plot for i = 1:num_bins; h = zeros(ceil(num_bins),1); h(i)=subplot(4,3,i); plotmatrix(current_rpm,current_torque

How to change the background colour of a subplot/inset in R?

吃可爱长大的小学妹 提交于 2019-12-05 02:46:04
问题 I'd like to add a subplot to an existing plot in R. The subplot (inset) should have a different background color. I tried the following: #install.packages("TeachingDemos", dependencies=T) library(package="TeachingDemos") d0 <- data.frame(x = rnorm(150, sd=5), y = rnorm(150, sd=5)) d0_inset <- data.frame(x = rnorm(1500, sd=5), y = rnorm(1500, sd=5)) plot(d0) subplot( fun = plot( d0_inset , col = 2 , pch = '.' , mgp = c(1,0.4,0) , ann = F , cex.axis=0.5 ) , x = grconvertX(c(0.75,1), from='npc')

How to add legend below subplots in matplotlib?

…衆ロ難τιáo~ 提交于 2019-12-04 19:35:56
I am trying to add a legend below a 3-column subplot figure. I have tried the following: fig, ax = plt.subplots(ncols=3) ax[0].plot(data1) ax[1].plot(data2) ax[2].plot(data3) ax_sub = plt.subplot(111) box = ax_sub.get_position() ax_sub.set_position([box.x0, box.y0 + box.height * 0.1,box.width, box.height * 0.9]) ax_sub.legend(['A', 'B', 'C'],loc='upper center', bbox_to_anchor=(0.5, -0.3),fancybox=False, shadow=False, ncol=3) plt.show() However, this creates just one empty frame. When I comment out the ax_sub part, my subplots show up nice (but without a legend...)... Many thanks! This is