Python Matplotlib How to create subplots? -
this question has answer here:
i having quite bit of trouble understanding how create subplots. want create figure similar 1 shown below. know how set similar template this?
also, how include these points error bars in subplots? code error bars:
mass, p, errp, errl = np.loadtxt('/users/shawn/desktop/vika1.dat', usecols = [0, 10, 11, 12], unpack = true) plt.errorbar(mass, np.log10(p) - 4, yerr = [np.log10(p) - np.log10(p-errl), np.log10(p + errp) - np.log10(p)], fmt = 'o', markerfacecolor = 'w', markeredgecolor = 'k', ecolor = 'k')
you use sharex , sharey share axes. following give layout want. can plot individual subplots using specific plot funcitons.
updated complete code below
import numpy np import matplotlib.pyplot plt fig, axes = plt.subplots(nrows=2, ncols=2, sharex=true, sharey=true) x = np.linspace(-np.pi, np.pi, 256, endpoint=true) c, s = np.cos(x), np.sin(x) axes[0,0].plot(x, c, color="blue", linewidth=1.0, linestyle="-") axes[0,1].plot(x, c, color="orange", linewidth=1.0, linestyle="-") axes[1,0].plot(x, c, color="green", linewidth=1.0, linestyle="-") axes[1,1].plot(x, c, color="red", linewidth=1.0, linestyle="-") plt.subplots_adjust(wspace=0,hspace=0) plt.show()
can't understand why has downvoted me initial answer...
the below lines prune min value both x , y axes thereby avoiding label overlaps
from matplotlib.ticker import maxnlocator axes[1,1].yaxis.set_major_locator(maxnlocator(prune='lower')) axes[1,1].xaxis.set_major_locator(maxnlocator(prune='lower'))
Comments
Post a Comment