Matplotlib
- Setting styles
- Adjusting the axis and fig parameters
- Colors
- Customization with seaborn
- Helper Functions
- Plot for the Blog Post
- Sources
- References
with plt.style.context('fivethirtyeight'):
plot()
You can even use a URL pounint to the style sheet. Source https://twitter.com/d_haitz/status/1277585108032258049
with plt.style.context('https://raw.githubusercontent.com/nickteff/EconomistStyle/master/theeconomist.mplstyle'):
plot()
x = np.linspace(-10, 10, 100)
with plt.style.context('fivethirtyeight'):
fig_kws = { 'facecolor': 'red',
'figsize':(14, 5),
'edgecolor':'k',
'linewidth':0,
'frameon': True,
'tight_layout': False,
'constrained_layout': True,
}
fig, axes = plt.subplots(**fig_kws)
axes.set(xlabel = 'X-Axis',
ylabel = "sine function",
title = "Demonstration of a title",
xlim=(-5, 5),
ylim = (-.9, .9),
xticks = [-.2,.2],
xticklabels =['a', 'b'],
yticks = [-.2,.2],
yticklabels =['a', 'b'],
facecolor = 'black',
yscale = 'linear', #log
xscale = 'linear'
)
axes.plot(x, np.sin(x))
color_list = ['#103657', '#164E66', '#44A1B2', '#7CAAD0',
'#B3BED0']
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=color_list)
plot()
def plot():
"Simple function to generate some plots."
fig, axes = plt.subplots(1, 3, tight_layout = True, figsize = (15, 5))
x = np.linspace(0, 5, 100)
for i in range(1, 6):
axes[0].plot(x, x ** i, linewidth = 5)
xx = np.random.randn(100)
xx.sort()
axes[1].plot(xx, xx.cumsum())
axes[2].hist(np.random.normal(size = 100))
Sources
-
[x] https://twitter.com/matplotlib/status/1256364300492513281
-
[ ] https://twitter.com/HillairetJulien/status/1291298772832657409
-
[ ] https://twitter.com/MilesCranmer/status/1290800078702116869
-
[ ] https://www.drawingfromdata.com/setting-figure-size-using-seaborn-and-matplotlib
- [ ] https://github.com/matplotlib/ipympl