subplot

Plotting a horizontal line on multiple subplots in python using pyplot

陌路散爱 提交于 2019-11-28 20:31:30
I am plotting three subplots on the same page. I want to draw a horiZontal line through all the subplots. Following is my code and the resultant graph: (You can notice I can get the horizontal line on one of the plots, but not all) gs1 = gridspec.GridSpec(8, 2) gs1.update(left=0.12, right=.94, wspace=0.12) ax1 = plt.subplot(gs1[0:2, :]) ax2 = plt.subplot(gs1[3:5, :], sharey=ax1) ax3 = plt.subplot(gs1[6:8, :], sharey=ax1) ax1.scatter(theta_cord, density, c = 'r', marker= '1') ax2.scatter(phi_cord, density, c = 'r', marker= '1') ax3.scatter(r_cord, density, c = 'r', marker= '1') ax1.set_xlabel(

How to reduce the borders around subplots in matlab? [duplicate]

天大地大妈咪最大 提交于 2019-11-28 16:20:30
Possible Duplicate: MATLAB subplot margin In matlab, an inordinate amount of space is wasted around subplots. For example, in this example: t = 0:0.001:2*pi+0.001; figure(2); for i = 1 : 25; subplot(5,5,i); plot(t, sin(i*t)); axis off end over 50% of the space on the figure is wasted as "blank" I'd like to shrink that blank space down, but have been unsuccessful to identify a mechanism to do so. Thoughts? Thanks John The subaxis function on the File Exchange allows you to specify margins for subplots. Example usage: t = 0:0.001:2*pi+0.001; figure(2); for i = 1 : 25; subaxis(5,5,i, 'Spacing', 0

Row and column headers in matplotlib's subplots

早过忘川 提交于 2019-11-28 15:42:38
What's the best practise to add a row and a column header to a grid of subplots generated in a loop in matplotlib ? I can think of a couple, but not particularly neat: For columns, with a counter to your loop you can use set_title() for the first row only. For rows this doesn't work. You would have to draw text outside of the plots. You add an extra row of subplots on top and an extra column of subplots on the left, and draw text in the middle of that subplot. Can you suggest a better alternative? Joe Kington There are several ways to do this. The easy way is to exploit the y-labels and titles

Plot something in one figure, and use it again later for another figure

一曲冷凌霜 提交于 2019-11-28 10:09:32
问题 I hope I'm asking this question at the right place. I have a for-loop, in that many figures are created. After the loop is finished I want to produce one more figure with three of those earlier created plots as suplots. My code right now is like this: import numpy as np import matplotlib.pyplot as plt def f(t): return np.exp(-t)*np.cos(2*np.pi*t)+(t/10)**2. t1=np.arange(0.0,5.0,0.1) t2=np.arange(0.0,5.0,0.02) for i in range(2): fig= plt.figure(i) ax1=fig.add_subplot(111) plt.title('Jon Snow')

Matplotlib: Getting subplots to fill figure

試著忘記壹切 提交于 2019-11-28 07:58:36
问题 I would please like suggestions for how to override the default matplotlib behaviour when plotting images as subplots, whereby the subplot sizes don't seem to match the figure size. I would like to set my figure size (e.g. to match the width of an A4 page) and have the subplots automatically stretch to fill the space available. In the following example, the code below gives a figure with a lot of white space between the panels: import numpy as np import matplotlib.pyplot as plt data=np.random

Matplotlib - adding subplots to a subplot?

我的梦境 提交于 2019-11-28 07:27:51
I'm trying to create a figure that consists of a 2x2 grid, where in each quadrant there are 2 vertically stacked subplots (i.e. a 2x1 grid). I can't seem to figure out how to achieve this, though. The closest I've gotten is using gridspec and some ugly code (see below), but because gridspec.update(hspace=X) changes the spacing for all of the subplots I'm still not where I'd like to be. Ideally what I want is to, using the picture below as an example, decrease the spacing between the subplots within each quadrant, while increasing the vertical spacing between the top and bottom quadrants (i.e.

python pandas DataFrame subplot in columns and rows

為{幸葍}努か 提交于 2019-11-28 07:09:18
问题 I would like to produce a subplot from data 4 column DataFrame into 2 rows and 2 columns df =pd.DataFrame(np.random.randn(6,4),index=pd.date_range('1/1/2000',periods=6, freq='1h')) However below will give a 4 row and 1 column plot df.plot(use_index=False, title=f, subplots=True, sharey=True, figsize=(8, 6)) Thanks. 回答1: cplcloud's answer works, but following code will give you a bit more structure so that you can start configuring more if you do not need the loop. fig, axes = plt.subplots

Second subplot disappearing

荒凉一梦 提交于 2019-11-28 03:52:13
问题 I have a weird (and probably simple to solve) problem. I tried to plot (using panel) two plots: a1 = subplot(2,1,1, 'Parent', handles.cpd_plot, 'Position', [0.1, 0.4, 0.85, 0.45]); a2 = subplot(2,1,2, 'Parent', handles.cpd_plot, 'Position', [0.1, 0.1, 0.85, 0.15]); but after plotting a2, a1 disappears. I see that its some problem with position, when I lift up a1 a bit ( 'Position', [0.1, 0.5, 0.85, 0.45] ) its working (but it has to be >= 0.5). Where is the problem? Thanks! 回答1: So it is

How to use matplotlib to create a large graph of subplots?

回眸只為那壹抹淺笑 提交于 2019-11-28 00:30:47
I am having trouble looping through each subplot. I reach the coordinates for the subplot, and then want different models to appear on each subplot. However, my current solution loops through all of the subplots, but at each one loops through all of the models, leaving the last model to be graphed at each subplot, meaning they all look the same. My goal is to place one model on every subplot. Please help! modelInfo = csv_info(filename) # obtains information from csv file f, axarr = plt.subplots(4, 6) for i in range(4): for j in range(6): for model in modelInfo: lat = dictionary[str(model) +

Multiple figures in a single window

冷暖自知 提交于 2019-11-28 00:25:46
I want to create a function which plot on screen a set of figures in a single window. By now I write this code: import pylab as pl def plot_figures(figures): """Plot a dictionary of figures. Parameters ---------- figures : <title, figure> dictionary """ for title in figures: pl.figure() pl.imshow(figures[title]) pl.gray() pl.title(title) pl.axis('off') It works perfectly but I would like to have the option for plotting all the figures in single window. And this code doesn't. I read something about subplot but it looks quite tricky. gcalmettes You can define a function based on the subplots