Create beautiful square figures with big labels and the correct number of ticks
def create_figure(size=3.6,nxticks=6): | |
import matplotlib | |
from matplotlib.ticker import MaxNLocator | |
figure=matplotlib.pyplot.figure(figsize=(size,size)) | |
ax = figure.add_subplot(1, 1, 1, position = [0.2, 0.15, 0.75, 0.75]) | |
ax.xaxis.set_major_locator(MaxNLocator(nxticks)) | |
return ax | |
def format_axes(ax,xf='%d',yf='%d',nxticks=6,nyticks=6,labelsize=10): | |
import pylab | |
from matplotlib.ticker import FormatStrFormatter, MaxNLocator | |
xFormatter = FormatStrFormatter(xf) | |
yFormatter = FormatStrFormatter(yf) | |
if xf: | |
ax.xaxis.set_major_formatter(xFormatter) | |
ax.xaxis.set_major_locator(MaxNLocator(nxticks)) | |
ax.tick_params(axis='x', which='major', labelsize=labelsize) | |
if yf: | |
ax.yaxis.set_major_formatter(yFormatter) | |
ax.yaxis.set_major_locator(MaxNLocator(nyticks)) | |
ax.tick_params(axis='y', which='major', labelsize=labelsize) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment