This is an example notebook for the prettyplotlib
plotting library. It is still under construction, so any feedback is welcome!
New syntax: Don't need to supply ax
everywhere!
For those of you using ppl.remove_chartjunk
, your code is now broken. Get it now via from prettyplotlib.utils import remove_chartjunk
import prettyplotlib as ppl
# Set the random seed for consistency
np.random.seed(12)
# Show the whole color range
for i in range(8):
x = np.random.normal(loc=i, size=1000)
y = np.random.normal(loc=i, size=1000)
ax = ppl.scatter(x, y, label=str(i))
ppl.legend(ax)
ax.set_title('prettyplotlib `scatter`')
<matplotlib.text.Text at 0x10adc2b90>
%load_ext autoreload
%autoreload 2
The autoreload extension is already loaded. To reload it, use: %reload_ext autoreload
import prettyplotlib as ppl
# Set the random seed for consistency
np.random.seed(12)
# Show the whole color range
for i in range(8):
y = np.random.normal(size=1000).cumsum()
x = np.arange(1000)
# For now, you need to specify both x and y :(
# Still figuring out how to specify just one
ppl.plot(x, y, label=str(i), linewidth=0.75)
ppl.legend()
<matplotlib.legend.Legend at 0x107a0b090>
fill_between
¶import prettyplotlib as ppl
# Set the random seed for consistency
np.random.seed(12)
# Show the whole color range
for i in range(8):
y1 = np.random.normal(size=1000).cumsum()
y2 = np.random.normal(size=1000).cumsum()
x = np.arange(1000)
ppl.fill_between(x, y1, y2, label=str(i))
ppl.legend()
fill_betweenx
¶import prettyplotlib as ppl
# Set the random seed for consistency
np.random.seed(12)
# Show the whole color range
for i in range(8):
y1 = np.random.normal(size=1000).cumsum()
y2 = np.random.normal(size=1000).cumsum()
x = np.arange(1000)
ppl.fill_betweenx(x, y1, y2, label=str(i))
ppl.legend()
pcolormesh
¶Save the fig
object that's returned because otherwise you see two of the same plot.
import prettyplotlib as ppl
from prettyplotlib import brewer2mpl
import numpy as np
import string
green_purple = brewer2mpl.get_map('PRGn', 'diverging', 11).mpl_colormap
np.random.seed(10)
fig = ppl.pcolormesh(np.random.randn(10,10),
xticklabels=string.uppercase[:10],
yticklabels=string.lowercase[-10:],
cmap=green_purple)
pcolormesh
: recenter the "0" value via center_value
¶fig = ppl.pcolormesh(np.random.randn(10,10),
xticklabels=string.uppercase[:10],
yticklabels=string.lowercase[-10:],
cmap=green_purple,
center_value=2)
import prettyplotlib as ppl
from prettyplotlib import brewer2mpl
import numpy as np
import string
green_purple = brewer2mpl.get_map('PRGn', 'diverging', 11).mpl_colormap
np.random.seed(10)
fig = ppl.pcolormesh(np.random.randn(10,10),
xticklabels=string.uppercase[:10],
yticklabels=string.lowercase[-10:],
cmap=green_purple,
center_value=2)
hist
¶import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(12)
# 'y' for the 'y' axis. Could also add a grid over the 'x' axis.
ppl.hist(np.random.randn(1000), grid='y')
<matplotlib.axes.AxesSubplot at 0x10b71b050>
bar
¶import prettyplotlib as ppl
import numpy as np
import string
np.random.seed(14)
n = 10
ppl.bar(np.arange(n), np.abs(np.random.randn(n)), annotate=True, grid='y')
<Container object of 10 artists>
barh
¶import prettyplotlib as ppl
import numpy as np
import string
np.random.seed(14)
n = 10
ppl.barh(np.arange(n), np.abs(np.random.randn(n)), annotate=True, grid='y')
<matplotlib.axes.AxesSubplot at 0x10b780650>
boxplot
¶import prettyplotlib as ppl
import matplotlib as mpl
np.random.seed(10)
data = np.random.randn(8, 4)
labels = ['A', 'B', 'C', 'D']
ppl.boxplot(data, xticklabels=labels)
<matplotlib.axes.AxesSubplot at 0x10b46e050>