PLOTS basicΒΆ

# -*-Python-*-
# Created by bgrierson at 13 Dec 2016  06:05

# This file style is an OMFITpythonTask
# You have to make your figure.

# Make x and two y variables
x = linspace(0, 1, 101) * 2.0 * np.pi
y1 = np.sin(x)
y2 = np.cos(x)

# Basic and explicit plotting of an array
figure()
plot(x, y1)

# ----
# Using plt.subplots
# ----
# Often want to do more than plot a single variable
# plt.subplots is a convenient way to get the handle of
# a plot and axes object
fig, ax = plt.subplots()
ax.plot(x, y1, label='sin')
ax.plot(x, y2, label='cos')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_title('Basic Overplotting')
ax.legend(loc='best').draggable()

# Now a more complex example with two panels that
# share an x-axis
fig, ax = plt.subplots(nrows=2, sharex=True)
ax[0].plot(x / 2.0 / np.pi, y1, ls='dashed', color='b', label='$sin(\\theta)$')
ax[0].axhline(0.0, ls='dashed', color='black')
ax[0].set_title('Basic Multi-panel Plotting')
# Text annotation in normalized coordinates
ax[0].text(0.2, 0.55, 'Zero Reference', transform=ax[0].transAxes)

ax[1].plot(x / 2.0 / np.pi, y2, marker='o', color='g', label='$cos(\\theta)$')
ax[1].axvline(0.5, ls='dashed', color='black')
ax[1].set_xlabel('$\\theta/\pi$')
# Text annotation in absolute coordinates
ax[1].text(0.51, 0.0, '$\\pi$ Reference')
for axi in ax.flatten():
    axi.legend().draggable()

# ----
# Using fig.use_subplot
# ----
fig = figure()
# Create a plot that is 3 rows and two columns and get reference to top-left plot
ax1 = fig.use_subplot(321)
ax1.plot(x, y1)
ax1.set_title('Basic add_subplot 321')
ax1.xaxis.set_visible(False)
# Add first column second row
ax2 = fig.use_subplot(323, sharex=ax1)
ax2.plot(x, y1)
ax2.set_title('Basic add_subplot 323')
ax2.xaxis.set_visible(False)
# Add first column third row
ax3 = fig.use_subplot(325, sharex=ax1)
ax3.plot(x, y1)
ax3.set_title('Basic add_subplot 325')
# Now make fourth plot a tall single column on right
ax4 = fig.use_subplot(122)
ax4.plot(x, y1)
ax4.set_title('Basic add_subplot 122')

# ----
# Using FigureNotebook
# ----
fn = FigureNotebook(0, 'Demo FigureNotebook')
fig, ax = fn.subplots(label='sin')
ax.plot(x, y1)
fig, ax = fn.subplots(label='cos')
ax.plot(x, y2)