Jupyter Snippet NP ch04-figures

Jupyter Snippet NP ch04-figures

Chapter 4: Figures

Robert Johansson

Source code listings for Numerical Python - Scientific Computing and Data Science Applications with Numpy, SciPy and Matplotlib (ISBN 978-1-484242-45-2).

%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib as mpl
fig = plt.figure()

ax = fig.add_axes([0.05, 0.05, .88, .88])
ax.set_yticks([])
ax.set_xticks([])
ax.text(0.001, 0.01, "(0,0)")
ax.text(1.001, 0.01, "(1,0)")
ax.text(0.001, 1.01, "(0,1)")
ax.text(1.001, 1.01, "(1,1)")
ax.text(0.02, 0.92, "Figure", fontsize=18)

ax.text(0.12, 0.06, "(0.15, 0.15)")

ax = fig.add_axes([0.15, 0.15, 0.68, 0.66])
ax.text(0.03, 0.88, "Axes", fontsize=18)
ax.set_yticks([])
ax.set_xticks([])


fig.savefig("figure-axes-schematic.pdf");

png

fig = plt.figure()


ax.text(0.12, 0.06, "(0.15, 0.15)")

ax = fig.add_axes([0.15, 0.15, 0.68, 0.66])
ax.set_yticks([1, 2, 3])
ax.set_xticks([1, 2, 3])

#ax.set_yticklabels(['', '', ''])

ax.set_xlabel("x axis", fontsize=18)
ax.set_ylabel("y axis", fontsize=18)

ax.set_xlim(1,3)
ax.set_ylim(1,3)

ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.25))
ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.25))

ax.annotate("Major tick",
         xy=(1, 2), xycoords='data',
         xytext=(+35, +30), textcoords='offset points', fontsize=16,
         arrowprops=dict(arrowstyle="->", connectionstyle="arc3, rad=.2"))

ax.annotate("Minor tick",
         xy=(1, 1.5), xycoords='data',
         xytext=(+35, +30), textcoords='offset points', fontsize=16,
         arrowprops=dict(arrowstyle="->", connectionstyle="arc3, rad=.2"))

fig.savefig("figure-axis-schematic.pdf");

png

Versions

%reload_ext version_information
%version_information numpy, matplotlib