DOS Multiplot
The pl.subplot2grid((nrow,ncol), (xn,yn)) allow us to create different plots
in the same canvas, nrow stands for the number of rows you desire as well as
ncols for the number of columns.xn,yn is the possition of the actual plot, for example (2,1)(0,0) means that there is a figure which contains 2 rows and one column and that actual plot is in the 1st column and the 1st row. (3,1),(2,0) means that you are ploting the 3rd plot from a figure which contains 4 rows.
We will use the same data as in the PROJECTED DENSITY OF STATES
Example: TiO2 density of states
import matplotlib.pyplot as pl import numpy as np from matplotlib import rcParams from matplotlib import gridspec import matplotlib.ticker as ticker # Load data with numpy libraries total = np.loadtxt('total_dos.dat') ti = np.loadtxt('ti_dos.dat') ox = np.loadtxt('ox_dos.dat') # Columns delimiters are simply blank spaces #----Adjust the draw into the canvas #-------------------------------------------- pl.subplots_adjust(left=0.10, bottom=0.10, right=0.98, top=0.98, wspace=0.35, hspace=None) #Figure 1 #---------------------------------- fig = pl.figure(1) (1,2) means figure will have 1 row 2 colums, and (0,0) is the location of figure 1 ax1=pl.subplot2grid((1,2), (0,0)) ax1.fill(total[:,0], total[:,7], label=''Total up', alpha=0.6, color='gray') ax1.fill(total[:,0], total[:,8], label=''Total down', alpha=0.6, color='gray') ax1.plot(ti[:,0], ti[:,5], label=''Ti (d) up', lw='1.2', color='blue') ax1.plot(ti[:,0], ti[:,6], label=''Ti (d) down', lw='1.2', color='blue') ax1.plot(ox[:,0], ox[:,3], label=''O (d) up', lw='2.0', color='red') ax1.plot(ox[:,0], ox[:,4], label=''O (d) down', lw='2.0', color='red') # Items for Figure 1 pl.xlabel(r'Energy [eV]', x=0.5, y=0) pl.ylabel('Density of States [states/eV]', x=0.0, y=0.5) pl.legend(loc=3, bbox_to_anchor=(0.20, 0.8), prop={'size':9}) pl.xlim( -8, 4) # X range pl.ylim(-15, 15) # Y range #Figure 2 #---------------------------------- fig = pl.figure(1) #(1,2) means figure will have 1 row 2 colums, #and (0,1) is the location of figure 2 ax1=pl.subplot2grid((1,2), (0,1)) ax1.fill(total[:,0], total[:,7], label=''Total up', alpha=0.6, color='gray') ax1.fill(total[:,0], total[:,8], label=''Total down', alpha=0.6, color='gray') ax1.plot(ti[:,0], ti[:,5], label=''Ti (d) up', lw='1.2', color='blue') ax1.plot(ti[:,0], ti[:,6], label=''Ti (d) down', lw='1.2', color='blue') ax1.plot(ox[:,0], ox[:,3], label=''O (d) up', lw='2.0', color='red') ax1.plot(ox[:,0], ox[:,4], label=''O (d) down', lw='2.0', color='red') # Items for Figure 2 pl.xlabel(r'Energy [eV]', x=0.5, y=0) pl.ylabel('Density of States [states/eV]', x=0.0, y=0.5) pl.legend(loc=3, bbox_to_anchor=(0.20, 0.8), prop={'size':9}) pl.xlim( -8, 4) # X range pl.ylim(-15, 15) # Y range pl.show()
Two plots with the same scale
Also you can create 2 or more plots in the same column, you just have to play with the subplot2grid((ncol,nrow),(xn,yn))
#----Adjust the draw into the canvas #-------------------------------------------- pl.subplots_adjust(left=0.10, bottom=0.10, right=0.98, top=0.98, wspace=0.35, hspace=None) #Figure 1 #---------------------------------- fig = pl.figure(1) ax1=pl.subplot2grid((2,1), (0,0)) # 2 rows 1 column ax1.axes.get_xaxis().set_visible(False) # Turns off xtics labels ax1.axes.get_yaxis().set_visible(True) # Turns on ytics labels (Default) pl.subplots_adjust(hspace=0) # Delete space between plots ax1.fill(total[:,0], total[:,7], label=''Total up', alpha=0.6, color='gray') ax1.fill(total[:,0], total[:,8], label=''Total down', alpha=0.6, color='gray') ax1.plot(ti[:,0], ti[:,5], label=''Ti (d) up', lw='1.2', color='blue') ax1.plot(ti[:,0], ti[:,6], label=''Ti (d) down', lw='1.2', color='blue') ax1.plot(ox[:,0], ox[:,3], label=''O (d) up', lw='2.0', color='red') ax1.plot(ox[:,0], ox[:,4], label=''O (d) down', lw='2.0', color='red') # Items for Figure 1 pl.xlim( -8, 4) # X range pl.ylim(-15, 15) # Y range #Figure 2 #---------------------------------- fig = pl.figure(1) ax1=pl.subplot2grid((2,1), (1,0)) # 2row,1col position 2nd row ax1.fill(total[:,0], total[:,7], label=''Total up', alpha=0.6, color='gray') ax1.fill(total[:,0], total[:,8], label=''Total down', alpha=0.6, color='gray') ax1.plot(ti[:,0], ti[:,5], label=''Ti (d) up', lw='1.2', color='blue') ax1.plot(ti[:,0], ti[:,6], label=''Ti (d) down', lw='1.2', color='blue') ax1.plot(ox[:,0], ox[:,3], label=''O (d) up', lw='2.0', color='red') ax1.plot(ox[:,0], ox[:,4], label=''O (d) down', lw='2.0', color='red') # Items for Figure 2 pl.xlabel(r'Energy [eV]', x=0.5, y=0) # Moves the y label between the two plots, thats why it says y=1 pl.ylabel('Density of States [states/eV]', x=0.0, y=1.0) pl.legend(loc=3, bbox_to_anchor=(0.50, 0.9), prop={'size':9}) pl.xlim( -8, 4) # X range pl.ylim(-15, 15) # Y range pl.show()
With some work you can create several plots that will enrich your work