Created
August 7, 2017 18:40
-
-
Save MattWoodhead/379808e3c6ea9ddd0213772f2d7e12a4 to your computer and use it in GitHub Desktop.
An up to date plotting example using some of the latest methods for simplifying subplots
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
import numpy as np | |
import matplotlib.pyplot as plt | |
# Create data | |
t1 = np.arange(0.0, 5.0, 0.1) | |
t2 = np.arange(0.0, 5.0, 0.02) | |
data1 = (t1, np.exp(t1) * np.cos(2*np.pi*t1)) | |
data2 = (t2, np.exp(t2) * np.cos(2*np.pi*t2)) | |
data3 = (t2, np.cos(2*np.pi*t2)) | |
# Settup Plot area | |
fig, axes = plt.subplots(nrows=2, ncols=1, sharex=True, sharey=False) | |
# First subplot | |
axes[0].plot(*data1, 'bo', | |
*data2, 'k') | |
axes[0].set(title="Plot 1", ylabel="Some Y values") | |
# Second subplot | |
axes[1].plot(*data3, 'r--') | |
axes[1].set(title="Plot 2", ylabel="More Y values", xlabel="Common X values") | |
# Adjust space between plots | |
plt.subplots_adjust(hspace=0.3) | |
# Add overall title to the plot area | |
plt.suptitle("Two Graphs") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment