-
-
Save abehmiel/066e38af300213a57baea71f78ec52ab 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 hidden or 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