subplot

Is it possible to automatically generate multiple subplots in matplotlib?

。_饼干妹妹 提交于 2019-12-10 10:42:10
问题 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

Pandas: set different ylim and titles for different subplots

☆樱花仙子☆ 提交于 2019-12-10 09:35:18
问题 Say I have this dataframe: Type Cat1 Cat2 Cat3 0 A 0.384000 0.393000 0.458000 1 B 0.603337 0.381470 0.299773 2 C 0.585797 0.452570 0.317607 3 D 0.324715 0.765212 0.717755 That I plot like this (from here): axes = df.set_index('Type').plot.bar(subplots=True, legend=False) plt.subplots_adjust(hspace=0.35) My problem: how can I set a different ylim for each subplot? And how can I modify things like the font size of the Cat titles? 回答1: the plotting method returns an array of axes in your axes

How can I programmatically select a specific subplot in Matplotlib?

放肆的年华 提交于 2019-12-09 05:18:52
问题 So in a figure where three vertical subplots have been added with add_subplot, how can I select let's say the middle one? Right now I do this list comprehension: [r[0] for r in sorted([[ax, ax.get_geometry()[2]] for ax in self.figure.get_axes()], key=itemgetter(1))] where I can simply select the index I want, with the corresponding axes . Is there a more straightforward way of doing this? 回答1: From the matplotlib documentation: If the figure already has a subplot with key (args, kwargs) then

How to manually position one subplot graph in matplotlib.pyplot

人盡茶涼 提交于 2019-12-09 03:03:28
How do I reposition the graph in the second row such that it is center aligned with respect to the WHOLE figure. On a more general note how to manually reposition the graph anywhere in the same row? import matplotlib.pyplot as plt m=0 for i in range(0,2): for j in range(0,2): if m <= 2: ax = plt.subplot2grid((2,2), (i,j)) ax.plot(range(0,10),range(0,10)) m = m+1 plt.show() Thank you. Using GridSpec , you can create a grid of any dimension that can be used for subplot placement. import matplotlib.gridspec as gridspec import matplotlib.pyplot as plt gs = gridspec.GridSpec(4, 4) ax1 = plt.subplot

Looping through a function to plot several subplots, Python

杀马特。学长 韩版系。学妹 提交于 2019-12-09 01:52:40
问题 I have variables x and y def function(a,b): x = x[(x>a)*(x<b)] y = y[(y<a)*(y>b)] # perform some fitting routine using curve_fit on x and y fig = plt.figure() ax = fig.add_subplot(111) phist,xedge,yedge,img = ax.hist2d(x,y,bins=20,norm=LogNorm()) im = ax.imshow(phist,cmap=plt.cm.jet,norm=LogNorm(),aspect='auto') fig.colorbar(im,ax=ax) fig.show() All works fine. But I have 6 pairs of different input parameters a and b . I would like to somehow call function(a,b) using a loop and plot the six

How to remove duplicate legend entries w/ plotly subplots()

为君一笑 提交于 2019-12-08 16:38:05
问题 How can I remove the duplicates in my legend when using plotly's subplots()? Here is my MWE: library(plotly) library(ggplot2) library(tidyr) mpg %>% group_by(class) %>% do(p = plot_ly(., x = ~cyl, y = ~displ, color = ~trans, type = 'bar')) %>% subplot(nrows = 2, shareX = TRUE, titleX = TRUE) %>% layout(barmode = 'stack') 回答1: Another workaround using the tidyverse . The following steps are added to the original MWE: Convert the trans column to a factor. Use tidyr's complete to fill (non-NA)

How to rewrite this Matlab 2014 code with axis-subplots to 2016?

假装没事ソ 提交于 2019-12-08 15:38:21
问题 Code which I wrote for Matlab 2014 but which I want to rewrite it to Matlab 2016 such that it becomes more compact, since it is extranous now hFig3=figure('Units', 'inches'); hax3_b1=axes('Parent', hFig3); hax3_b2=axes('Parent', hFig3); hax3_b3=axes('Parent', hFig3); hax3_b4=axes('Parent', hFig3); b1=subplot(2,2,1, hax3_b1); b2=subplot(2,2,2, hax3_b2); b3=subplot(2,2,3, hax3_b3); b4=subplot(2,2,4, hax3_b4); % Example of common expression set([b1 b2], 'Units', 'inches'); % http://stackoverflow

How to manually position one subplot graph in matplotlib.pyplot

独自空忆成欢 提交于 2019-12-08 08:16:01
问题 How do I reposition the graph in the second row such that it is center aligned with respect to the WHOLE figure. On a more general note how to manually reposition the graph anywhere in the same row? import matplotlib.pyplot as plt m=0 for i in range(0,2): for j in range(0,2): if m <= 2: ax = plt.subplot2grid((2,2), (i,j)) ax.plot(range(0,10),range(0,10)) m = m+1 plt.show() Thank you. 回答1: Using GridSpec, you can create a grid of any dimension that can be used for subplot placement. import

Matplotlib show x-ticks on all subplots and unique y label

岁酱吖の 提交于 2019-12-08 05:07:50
问题 I am plotting two subplots that share the same x-axis but when I plot I only see the x-axis ticks on the second subplot. How can I make the x-ticks visible on both subplots? Also I would like to set y-labels for both subplots but only the second is visible. Can you please help in displaying the y-label on both subplots? Below is my reproducible code. #!/usr/bin/python3 import pandas as pd desired_width = 1500 pd.set_option('display.width', desired_width) import matplotlib.pyplot as plt import

How do I position subplots in MATLAB?

柔情痞子 提交于 2019-12-08 01:59:11
问题 I have problem to set the position of subplots. I'm using subplot inside a loop. But when I try to make special position to the subplots it doesn't work. This is my code: h=subplot(2,2,3); set(h,'position',[0.15 0.15 0.4 0.4]); plot(d3,S3,'*','Color',colors(i,:)); I tried different methods but can't see the third subplot, and sometimes the plot shows only one iteration. How can I fix this? 回答1: This create 3 subplots. Position is [left bottom width height]). I usually try to make sure that