how to make 3X1, 2X1 etc multipanel plots in matplotlib. Here is the code I used
-*- coding: utf-8 -*-
"""
Created on Thu May 2 20:08:48 2019
@author: tsparks
"""
#grab libraries
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
import matplotlib as mpl
mpl.rcParams['pdf.fonttype'] = 42
#grab dataset 1
filename = r'example.csv'
df = pd.read_csv(filename)
#pull data from CSV
x_data = df['x'].dropna()
y_data = df['y'].dropna()
x_error = df['x error'].dropna()
y_error = df['y error'].dropna()
#Set the limits of the plot for dataset1
xmin1=0
xmax1=16
ymin1=0
ymax1=60
#grab dataset 2
filename = r'example2.csv'
df = pd.read_csv(filename)
#pull data from CSV
x_data2 = df['x'].dropna()
y_data2 = df['y'].dropna()
x_error2 = df['x error'].dropna()
y_error2 = df['y error'].dropna()
#Set the limits of the plot for dataset1
xmin2=0
xmax2=16
ymin2=-5
ymax2=5
#Generate some nice colors
seshadri = ['#c3121e', '#0348a1', '#ffb01c', '#027608', '#0193b0', '#9c5300', '#949c01', '#7104b5']
0sangre, 1neptune, 2pumpkin, 3clover, 4denim, 5cocoa, 6cumin, 7berry
#Prepare multipanel plot
fig = plt.figure(1, figsize=(5, 5))
gs = gridspec.GridSpec(4,3)
gs.update(wspace=0.25, hspace=0.45)
#Generate first panel
xtr_subsplot = fig.add_subplot(gs[0:2,0:3])
plt.errorbar(x_data, y_data, xerr=x_error, yerr=y_error, label='data', linestyle='none', marker='o', color=seshadri[1], markerfacecolor='none', markersize=6) # plot data
plt.tick_params(direction='in',right=True, top=True)
plt.tick_params(labelbottom=True, labeltop=False, labelright=False, labelleft=True)
xticks = np.arange(0,(xmax1+1),(xmax1/4))
yticks = np.arange(0,(ymax1+1),(ymax1/3))
plt.minorticks_on()
plt.tick_params(direction='in',which='minor', length=5, bottom=True, top=True, left=True, right=True)
plt.tick_params(direction='in',which='major', length=10, bottom=True, top=True, left=True, right=True)
plt.xticks(xticks)
plt.yticks(yticks)
plt.legend()
plt.xlim(xmin1,xmax1)
plt.ylabel('y label (units)')
#generate second panel
xtr_subsplot = fig.add_subplot(gs[2:4,0:3])
plt.errorbar(x_data2, y_data2, xerr=x_error2, yerr=y_error2, label='data', linestyle='none', marker='o', color=seshadri[2], markerfacecolor='none', markersize=6) # plot data
plt.tick_params(direction='in',right=True, top=True)
plt.tick_params(labelbottom=True, labeltop=False, labelright=False, labelleft=True)
xticks = np.arange(0,(xmax2+1),(xmax2/4))
yticks = np.arange(-6,6.1,3)
plt.minorticks_on()
plt.tick_params(direction='in',which='minor', length=5, bottom=True, top=True, left=True, right=True)
plt.tick_params(direction='in',which='major', length=10, bottom=True, top=True, left=True, right=True)
plt.xticks(xticks)
plt.yticks(yticks)
plt.legend()
plt.xlim(xmin2,xmax2)
plt.xlabel('x label (units)')
plt.ylabel('y label (units)')
#Export figure
plt.savefig('multi_panel_error.pdf')
plt.savefig('multi_panel_error.png', dpi=300,bbox_inches="tight")
Nesta página do site você pode assistir ao vídeo on-line multipanel plots in python matplotlib duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Taylor Sparks 16 Setembro 2019, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,439 vezes e gostou 20 espectadores. Boa visualização!