Setting styles

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()

Adjusting the axis and fig parameters

We can customize a lot of the figure like the label, or title via the set command.

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))

Colors

color_list = ['#103657', '#164E66', '#44A1B2', '#7CAAD0',
              '#B3BED0']
plt.rcParams['axes.prop_cycle'] = plt.cycler(color=color_list)
plot()

Customization with seaborn

Helper Functions

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))

Plot for the Blog Post

References