<jupyter_start><jupyter_text>Customizing Matplotlib: Configurations and Stylesheets  Plot Customization by HandThrough this chapter, we've seen how it is possible to tweak individual plot settings to end up with something that looks a little bit nicer than the default.It's possible to do these customizations for each individual plot.For example, here is a fairly drab default histogram:<jupyter_code>import matplotlib.pyplot as plt
plt.style.use('classic')
import numpy as np
x = np.random.randn(1000)
plt.hist(x);<jupyter_output><empty_output><jupyter_text>We can adjust this by hand to make it a much more visually pleasing plot:  StylesheetsThe version 1.4 release of Matplotlib in August 2014 added a very convenient ``style`` module, which includes a number of new default stylesheets, as well as the ability to create and package your own styles. These stylesheets are formatted similarly to the *.matplotlibrc* files mentioned earlier, but must be named with a *.mplstyle* extension.Even if you don't create your own style, the stylesheets included by default are extremely useful.The available styles are listed in ``plt.style.available``—here I'll list only the first five for brevity:<jupyter_code>plt.style.available[:5]<jupyter_output><empty_output><jupyter_text>The basic way to switch to a stylesheet is to call``` pythonplt.style.use('stylename')```But keep in mind that this will change the style for the rest of the session!Alternatively, you can use the style context manager, which sets a style temporarily:``` pythonwith plt.style.context('stylename'):    make_a_plot()``` Let's create a function that will make two basic types of plot:<jupyter_code>def hist_and_lines():
    np.random.seed(0)
    fig, ax = plt.subplots(1, 2, figsize=(11, 4))
    ax[0].hist(np.random.randn(1000))
    for i in range(3):
        ax[1].plot(np.random.rand(10))
    ax[1].legend(['a', 'b', 'c'], loc='lower left')<jupyter_output><empty_output><jupyter_text>We'll use this to explore how these plots look using the various built-in styles.  FiveThiryEight styleThe ``fivethirtyeight`` style mimics the graphics found on the popular [FiveThirtyEight website](https://fivethirtyeight.com).As you can see here, it is typified by bold colors, thick lines, and transparent axes:<jupyter_code>with plt.style.context('fivethirtyeight'):
    hist_and_lines()<jupyter_output><empty_output><jupyter_text>ggplotThe ``ggplot`` package in the R language is a very popular visualization tool.Matplotlib's ``ggplot`` style mimics the default styles from that package:<jupyter_code>with plt.style.context('ggplot'):
    hist_and_lines()<jupyter_output><empty_output><jupyter_text>*Bayesian Methods for Hackers( styleThere is a very nice short online book called [*Probabilistic Programming and Bayesian Methods for Hackers*](http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/); it features figures created with Matplotlib, and uses a nice set of rc parameters to create a consistent and visually-appealing style throughout the book.This style is reproduced in the ``bmh`` stylesheet:<jupyter_code>with plt.style.context('bmh'):
    hist_and_lines()<jupyter_output><empty_output><jupyter_text>Dark backgroundFor figures used within presentations, it is often useful to have a dark rather than light background.The ``dark_background`` style provides this:<jupyter_code>with plt.style.context('dark_background'):
    hist_and_lines()<jupyter_output><empty_output><jupyter_text>GrayscaleSometimes you might find yourself preparing figures for a print publication that does not accept color figures.For this, the ``grayscale`` style, shown here, can be very useful:<jupyter_code>with plt.style.context('grayscale'):
    hist_and_lines()<jupyter_output><empty_output><jupyter_text>Seaborn styleMatplotlib also has stylesheets inspired by the Seaborn library (discussed more fully in [Visualization With Seaborn](04.14-Visualization-With-Seaborn.ipynb)).As we will see, these styles are loaded automatically when Seaborn is imported into a notebook.I've found these settings to be very nice, and tend to use them as defaults in my own data exploration.<jupyter_code>import seaborn
hist_and_lines()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08564705882352941, 'fraction_numerical': 0.007294117647058823, 'mean_word_length': 6.291595197255575, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '515501', 'license': 'MIT', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1211, 'n_words': 454, 'path': '#3 Data Manipulation & Visualization/Visualization/#3.2.12 - Settings and Stylesheets.ipynb', 'repo_name': 'Sphincz/dsml', 'size': '4250'}