subplot

How can I change the font size of ticks of axes object in matplotlib [duplicate]

拟墨画扇 提交于 2019-12-03 10:50:23
问题 This question already has answers here : Matplotlib make tick labels font size smaller (10 answers) Closed 2 years ago . I have a figure I added subfigure to (inset). I have used: fig = plt.figure() ax = fig.add_subplot(111) subA = fig.add_axes([0.4,0.14,0.2,0.2]) I now want to change the xtick font size of the subfigure. I tried some naive approach such as subA.get_xaxis().get_xticks().set_fontsize(10) without any luck. How can I do this then? 回答1: Use: subA.tick_params(labelsize=6) 回答2: fig

Removing frame while keeping axes in pyplot subplots

有些话、适合烂在心里 提交于 2019-12-03 09:36:40
问题 I am creating a figure with 3 subplots, and was wondering if there is any way of removing the frame around them, while keeping the axes in place? 回答1: If you want to remove the axis spines, but not the other information (ticks, labels, etc.), you can do that like so: fig, ax = plt.subplots(7,1, sharex=True) t = np.arange(0, 1, 0.01) for i, a in enumerate(ax): a.plot(t, np.sin((i + 1) * 2 * np.pi * t)) a.spines["top"].set_visible(False) a.spines["right"].set_visible(False) a.spines["bottom"]

Axes from plt.subplots() is a “numpy.ndarray” object and has no attribute “plot”

六眼飞鱼酱① 提交于 2019-12-03 09:34:46
问题 The information below may be superfluous if you are trying to understand the error message. Please start off by reading the answer by @user707650 . Using MatPlotLib, I wanted a generalizable script that creates the following from my data. A window containing a subplots arranged so that there are b subplots per column. I want to be able to change the values of a and b . If I have data for 2a subplots, I want 2 windows, each with the previously described " a subplots arranged according to b

Matplotlib: Repositioning a subplot in a grid of subplots

让人想犯罪 __ 提交于 2019-12-03 06:56:23
I am trying to make a plot with 7 subplots. At the moment I am plotting two columns, one with four plots and the other with three, i.e. like this: I am constructing this plot in the folowing way: #! /usr/bin/env python import numpy as plotting import matplotlib from pylab import * x = np.random.rand(20) y = np.random.rand(20) fig = figure(figsize=(6.5,12)) subplots_adjust(wspace=0.2,hspace=0.2) iplot = 420 for i in range(7): iplot += 1 ax = fig.add_subplot(iplot) ax.plot(x,y,'ko') ax.set_xlabel("x") ax.set_ylabel("y") savefig("subplots_example.png",bbox_inches='tight') However, for publication

How can I programmatically select a specific subplot in Matplotlib?

偶尔善良 提交于 2019-12-03 05:59:54
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? Yann From the matplotlib documentation : If the figure already has a subplot with key (args, kwargs) then it will simply make that subplot current and return it. Here's an example: import matplotlib.pyplot

figure.add_subplot() vs pyplot.subplot()

非 Y 不嫁゛ 提交于 2019-12-03 05:54:13
What is the difference between add_subplot() and subplot() ? They both seem to add a subplot if one isn't there. I looked at the documentation but I couldn't make out the difference. Is it just for making future code more flexible? For example: fig = plt.figure() ax = fig.add_subplot(111) vs plt.figure(1) plt.subplot(111) from matplotlib tutorials. If you need a reference to ax for later use: ax = fig.add_subplot(111) gives you one while with: plt.subplot(111) you would need to do something like: ax = plt.gca() Likewise, if want to manipulate the figure later: fig = plt.figure() gives you a

How do I change matplotlib's subplot projection of an existing axis?

你。 提交于 2019-12-03 05:23:26
I'm trying to construct a simple function that takes a subplot instance ( matplotlib.axes._subplots.AxesSubplot ) and transforms its projection to another projection, for example, to one of the cartopy.crs.CRS projections. The idea looks something like this import cartopy.crs as ccrs import matplotlib.pyplot as plt def make_ax_map(ax, projection=ccrs.PlateCarree()): # set ax projection to the specified projection ... # other fancy formatting ax2.coastlines() ... # Create a grid of plots fig, (ax1, ax2) = plt.subplots(ncols=2) # the first subplot remains unchanged ax1.plot(np.random.rand(10)) #

How can I align plots/graphics in subplots in MATLAB?

隐身守侯 提交于 2019-12-03 03:41:15
I have 3 objects (a photo and 2 plots) to put into subplots on one figure. It should look like this: But as one can notice, the photo should not be square but rectangle. I tried to make it this way (found here Matlab: How to align the axes of subplots when one of them contains a colorbar? ): main=subplot(4,4,[5,6,7,9,10,11,13,14,15]) %photo imagesc(im); axis('image') pion=subplot(4,4,[8,12,16]); %right plot (rotated) view(90, 90) plot(ypion,Ppion,'.k'); poz=subplot(4,4,1:3); %upper plot plot(xpoz,Ppoz,'.k'); pos1=get(poz,'Position') pos2=get(main,'Position') pos3=get(pion,'Position') pos1(3) =

Axes from plt.subplots() is a “numpy.ndarray” object and has no attribute “plot”

家住魔仙堡 提交于 2019-12-03 01:50:22
The information below may be superfluous if you are trying to understand the error message. Please start off by reading the answer by @user707650 . Using MatPlotLib, I wanted a generalizable script that creates the following from my data. A window containing a subplots arranged so that there are b subplots per column. I want to be able to change the values of a and b . If I have data for 2a subplots, I want 2 windows, each with the previously described " a subplots arranged according to b subplots per column". The x and y data I am plotting are floats stored in np.arrays and are structured as

Matplotlib: get and set axes position

只谈情不闲聊 提交于 2019-12-03 01:43:00
In matlab, it's straightforward to get and set the position of an existing axes on the figure: pos = get(gca(), 'position') set(gca(), 'position', pos) How do I do this in Matplotlib? I need this for two related reasons: These are the specific problems I'm trying to solve: I have a column of subplots where some have colorbars and some don't, and they aren't the same width i.e. the X axises don't align. The colorbar steals space from the axes. This also happens in matlab, and there I'd use the above trick to make all the axes equally wide by copying the width from an axes with a colorbar to