Adding subplots to a subplot

You can nest your GridSpec using SubplotSpec. The outer grid will be a 2 x 2 and the inner grids will be 2 x 1. The following code should give you the basic idea. import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec fig = plt.figure(figsize=(10, 8)) outer = gridspec.GridSpec(2, 2, wspace=0.2, hspace=0.2) for i in … Read more

Can I create AxesSubplot objects, then add them to a Figure instance?

Typically, you just pass the axes instance to a function. For example: import matplotlib.pyplot as plt import numpy as np def main(): x = np.linspace(0, 6 * np.pi, 100) fig1, (ax1, ax2) = plt.subplots(nrows=2) plot(x, np.sin(x), ax1) plot(x, np.random.random(100), ax2) fig2 = plt.figure() plot(x, np.cos(x)) plt.show() def plot(x, y, ax=None): if ax is None: ax … Read more

How to change size of figure with subplots

You can remove your initial plt.figure(). When calling plt.subplots() a new figure is created, so you first call doesn’t do anything. The subplots command in the background will call plt.figure() for you, and any keywords will be passed along. So just add the figsize keyword to the subplots() command: def plot(reader): channels=[] for i in … Read more

Change spacing of dashes in dashed line in matplotlib [duplicate]

You can directly specify the dashes length/space using the dashes=(length, interval space) argument inside the plot command. import matplotlib.pyplot as plt fig,ax = plt.subplots() ax.plot([0, 1], [0, 1], linestyle=”–“, dashes=(5, 1)) #length of 5, space of 1 ax.plot([0, 1], [0, 2], linestyle=”–“, dashes=(5, 5)) #length of 5, space of 5 ax.plot([0, 1], [0, 3], linestyle=”–“, … Read more

Python: subplot within a loop: first panel appears in wrong position

Using your code with some random data, this would work: fig, axs = plt.subplots(2,5, figsize=(15, 6), facecolor=”w”, edgecolor=”k”) fig.subplots_adjust(hspace = .5, wspace=.001) axs = axs.ravel() for i in range(10): axs[i].contourf(np.random.rand(10,10),5,cmap=plt.cm.Oranges) axs[i].set_title(str(250+i)) The layout is off course a bit messy, but that’s because of your current settings (the figsize, wspace etc).

Rotate tick labels in subplot

You can do it in multiple ways: Here is one solution making use of tick_params: ax.tick_params(labelrotation=45) Here is another solution making use of set_xticklabels: ax.set_xticklabels(labels, rotation=45) Here is a third solution making use of set_rotation: for tick in ax.get_xticklabels(): tick.set_rotation(45)

Row titles for matplotlib subplot

New in matplotlib 3.4.0 Row titles can now be implemented as subfigure suptitles: The new subfigure feature allows creating virtual figures within figures with localized artists (e.g., colorbars and suptitles) that only pertain to each subfigure. See how to plot subfigures for further details. How to reproduce OP’s reference figure: Either Figure.subfigures (most straightforward) Create … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)