DekGenius.com
TYPESCRIPT
subplots matplotlib examples
fig, axs = plt.subplots(2, 2)
axs[0, 0].plot(x, y)
axs[0, 0].set_title("main")
axs[1, 0].plot(x, y**2)
axs[1, 0].set_title("shares x with main")
axs[1, 0].sharex(axs[0, 0])
axs[0, 1].plot(x + 1, y + 1)
axs[0, 1].set_title("unrelated")
axs[1, 1].plot(x + 2, y + 2)
axs[1, 1].set_title("also unrelated")
fig.tight_layout()
matplotlib subplots
# Example with 3 figures (more can be added)
fig, (fig1, fig2, fig3) = plt.subplots(1, 3) # subplots(row, columns)
fig1.plot(x,y)
fig2.plot(x,y)
fig3.plot(x,y)
plt.show()
get subplots in matplotlib
fig,ax = plt.subplots(3,2,figsize=(25,10),)
i,j = 0,0
for each in list_of_images:
img = cv.imread(each.name)
ax[i,j].imshow(img)
if j == 1:
j = 0
if i != 2:
i += 1
else:
j += 1
subplots in subplots
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 range(4):
inner = gridspec.GridSpecFromSubplotSpec(2, 1,
subplot_spec=outer[i], wspace=0.1, hspace=0.1)
for j in range(2):
ax = plt.Subplot(fig, inner[j])
t = ax.text(0.5,0.5, 'outer=%d, inner=%d' % (i, j))
t.set_ha('center')
ax.set_xticks([])
ax.set_yticks([])
fig.add_subplot(ax)
fig.show()
subplots matplotlib
# using the variable ax for single a Axes
fig, ax = plt.subplots()
# using the variable axs for multiple Axes
fig, axs = plt.subplots(2, 2)
# using tuple unpacking for multiple Axes
fig, (ax1, ax2) = plt.subplot(1, 2)
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplot(2, 2)
subplots matplotlib
fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharey=True)
fig.suptitle('Initial Pokemon - 1st Generation')
# Bulbasaur
sns.barplot(ax=axes[0], x=bulbasaur.index, y=bulbasaur.values)
axes[0].set_title(bulbasaur.name)
# Charmander
sns.barplot(ax=axes[1], x=charmander.index, y=charmander.values)
axes[1].set_title(charmander.name)
# Squirtle
sns.barplot(ax=axes[2], x=squirtle.index, y=squirtle.values)
axes[2].set_title(squirtle.name)
plt.subplot python
plt.subplot(nb_rows, nb_cols, position)
subplots matplotlib
fig, (ax1, ax2) = plt.subplots(2)
fig.suptitle('Vertically stacked subplots')
ax1.plot(x, y)
ax2.plot(x, -y)
#or
fig, (ax1, ax2) = plt.subplots(1,2) #in lines
© 2022 Copyright:
DekGenius.com