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
# taken from Coursera | |
import mpl_toolkits.axes_grid1.inset_locator as mpl_il | |
plt.figure() | |
plt.boxplot([ df['normal'], df['random'], df['gamma'] ], whis='range') | |
# overlay axis on top of another | |
# create an inset using .inset_axes() | |
ax2 = mpl_il.inset_axes(plt.gca(), width='60%', height='40%', loc=2) #loc 5 (center right) = loc 7 (right) |
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
import matplotlib.pyplot as plt | |
k = np.array([1, 4, 9, 16, 25, 36, 49, 64]) | |
plt.figure() | |
y,bins,p=plt.hist(k, edgecolor='black') | |
print("", y, "\n", bins, "\n", p) |
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
import numpy as np | |
a = np.array([1,2,3,5,8,13,21,34]) | |
b = np.array([1, 4, 9, 16, 25, 36, 49, 64]) | |
c = np.linspace(0, 40, 8) | |
d = np.sin(c) | |
plt.figure() | |
plt.plot(a) | |
plt.plot(a, 'go') # 1 |
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
# modified from: https://matplotlib.org/gallery/userdemo/demo_gridspec02.html#sphx-glr-gallery-userdemo-demo-gridspec02-py | |
import matplotlib.pyplot as plt | |
from matplotlib.gridspec import GridSpec | |
Y = np.random.normal(loc=0.0, scale=1.0, size=10000) | |
X = np.random.random(size=10000) | |
a = np.array([1,2,3,5,8,13,21,34]) | |
b = np.array([1, 4, 9, 16, 25, 36, 49, 64]) | |
fig = plt.figure() |
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
# from matplotlib | |
import matplotlib.pyplot as plt | |
from matplotlib.gridspec import GridSpec | |
def make_ticklabels_invisible(fig): | |
for i, ax in enumerate(fig.axes): | |
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center") | |
ax.tick_params(labelbottom=False, labelleft=False) |
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
# from matplotlib.org | |
import matplotlib.pyplot as plt | |
from matplotlib.gridspec import GridSpec | |
def make_ticklabels_invisible(fig): | |
for i, ax in enumerate(fig.axes): | |
ax.text(0.5, 0.5, "ax%d" % (i+1), va="center", ha="center") | |
ax.tick_params(labelbottom=False, labelleft=False) |
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
# create 2x2 grid of axis subplots | |
fig, ((ax1, ax2, ax3), (ax4, ax5, ax6), (ax7, ax8, ax9)) = plt.subplots(3, 3, sharex=True) | |
axs = [ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9] | |
# draw n = 10, 100, 1000, and 10000 samples from the normal distribution and plot corresponding histograms | |
for n in range(0,len(axs)): | |
axs[n].plot(x, y) | |
.....<continue your script > |
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
# modified from Coursera | |
# figure 2: Creates two subplots and unpacks the output array immediately | |
# 1st subplot | |
plt.subplot(2,2,1) | |
plt.plot(x, y) | |
plt.title('Sharing Y axis') # set_title() is owned by axes, not plt. | |
# 2nd subplot | |
plt.subplot(2, 2, 4) | |
plt.scatter(x, y) |
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
# modified from Coursera | |
# figure 2: Creates two subplots and unpacks the output array immediately | |
f, ax = plt.subplots(2, 2, sharey=True) | |
ax[0,0].plot(x, y) | |
ax[0,0].set_title('Sharing Y axis') | |
ax[1,1].scatter(x, y) |
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
# Modified from Coursera.org | |
%matplotlib notebook | |
import numpy as np | |
import matplotlib.pyplot as plt | |
x = np.linspace(0, 2*np.pi, 400) | |
y = np.sin(x**2) | |
# figure 2: Creates two subplots and unpacks the output array immediately |