Created
October 31, 2017 21:06
-
-
Save corbett/be8b9da03a86ba62e01e74de658abf90 to your computer and use it in GitHub Desktop.
Create beautiful square figures with big labels and the correct number of ticks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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