Learn practical skills, build real-world projects, and advance your career
Updated 2 years ago
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from cycler import cycler
plt.style.use('ggplot')
data = np.random.randn(50)
To list all available styles, use:
print(plt.style.available)
['Solarize_Light2', '_classic_test_patch', 'bmh', 'classic', 'dark_background', 'fast', 'fivethirtyeight', 'ggplot', 'grayscale', 'seaborn', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark', 'seaborn-dark-palette', 'seaborn-darkgrid', 'seaborn-deep', 'seaborn-muted', 'seaborn-notebook', 'seaborn-paper', 'seaborn-pastel', 'seaborn-poster', 'seaborn-talk', 'seaborn-ticks', 'seaborn-white', 'seaborn-whitegrid', 'tableau-colorblind10']
DEFINING YOUR OWN STYLE
>>> import matplotlib.pyplot as plt
>>> plt.style.use('./images/presentation.mplstyle')
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\desktop\anaconda3\lib\site-packages\matplotlib\style\core.py in use(style)
120 try:
--> 121 rc = rc_params_from_file(style, use_default_template=False)
122 _apply_style(rc)
~\desktop\anaconda3\lib\site-packages\matplotlib\__init__.py in rc_params_from_file(fname, fail_on_error, use_default_template)
882 """
--> 883 config_from_file = _rc_params_in_file(fname, fail_on_error=fail_on_error)
884
~\desktop\anaconda3\lib\site-packages\matplotlib\__init__.py in _rc_params_in_file(fname, transform, fail_on_error)
811 rc_temp = {}
--> 812 with _open_file_or_url(fname) as fd:
813 try:
~\desktop\anaconda3\lib\contextlib.py in __enter__(self)
112 try:
--> 113 return next(self.gen)
114 except StopIteration:
~\desktop\anaconda3\lib\site-packages\matplotlib\__init__.py in _open_file_or_url(fname)
789 encoding = "utf-8"
--> 790 with open(fname, encoding=encoding) as f:
791 yield f
FileNotFoundError: [Errno 2] No such file or directory: './images/presentation.mplstyle'
The above exception was the direct cause of the following exception:
OSError Traceback (most recent call last)
<ipython-input-3-daad28dd7ec7> in <module>
1 import matplotlib.pyplot as plt
----> 2 plt.style.use('./images/presentation.mplstyle')
~\desktop\anaconda3\lib\site-packages\matplotlib\style\core.py in use(style)
122 _apply_style(rc)
123 except IOError as err:
--> 124 raise IOError(
125 "{!r} not found in the style library and input is not a "
126 "valid URL or path; see `style.available` for list of "
OSError: './images/presentation.mplstyle' not found in the style library and input is not a valid URL or path; see `style.available` for list of available styles