Skip to content

Instantly share code, notes, and snippets.

@ngoldbaum
Last active May 31, 2016 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngoldbaum/67cf464cc1e2763f95808759423943d9 to your computer and use it in GitHub Desktop.
Save ngoldbaum/67cf464cc1e2763f95808759423943d9 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.figure
from matplotlib.font_manager import FontProperties
from matplotlib.backends.backend_agg import FigureCanvasAgg
font_path = matplotlib.get_data_path() + '/fonts/ttf/STIXGeneral.ttf'
fp = FontProperties(**{'fname': font_path, 'size': 18})
fig = matplotlib.figure.Figure()
ax = fig.add_axes([0.1, 0.2, 0.8, 0.7])
im = ax.imshow(np.random.random((800, 800)))
cb = fig.colorbar(im)
cbax = cb.ax
ax.set_xlabel('x label')
ax.set_ylabel(r'$y\ label$')
cb.set_label('colorbar label')
labels = ax.xaxis.get_ticklabels() + ax.yaxis.get_ticklabels()
labels += cbax.yaxis.get_ticklabels()
labels += [ax.title, ax.xaxis.label, ax.yaxis.label,
cbax.yaxis.label, cbax.yaxis.get_offset_text(),
ax.xaxis.get_offset_text(), ax.yaxis.get_offset_text()]
for label in labels:
label.set_fontproperties(fp)
canvas = FigureCanvasAgg(fig)
canvas.print_figure('test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment