Matplotlib plotting styles
This blog is generated from notebook. Please go to here to get a better reading experience.
Matplotlib plot styles overview
The default style of matplotlib doesn’t look good. Fortunately, matplotlib supplies more sytles since 1.4.3. The version I’m using is 1.5.1, which has more styles to choose.
To check the matplotlib version:
In [1]:
matplotlib version 1.5.1
Python version 3.5.1 (default, Dec 20 2015, 12:06:42)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
In order to have a more intuitive understanding of different styles, I will list all the styles available, and draw bar charts with each style. In each bar chart, we draw the bars with the colors in the current style.
First, import related libraries, matplotlib and numpy.
In [2]:
Then, we can list and print all the available styles:
In [3]:
['seaborn-ticks',
'seaborn-talk',
'seaborn-darkgrid',
'seaborn-dark-palette',
'fivethirtyeight',
'seaborn-white',
'seaborn-muted',
'seaborn-bright',
'bmh',
'seaborn-whitegrid',
'seaborn-pastel',
'classic',
'ggplot',
'seaborn-deep',
'seaborn-poster',
'seaborn-colorblind',
'seaborn-paper',
'seaborn-notebook',
'seaborn-dark',
'grayscale',
'dark_background']
For different styles, the colormaps are different, create a method to get the colors:
In [4]:
Create a method to set the face color of different bars in a bar chart:
In [5]:
Then, create a figure, set the height according the count of styles. Here we want to plot all the different styles into 2 columns subplots, so we devide the height with 2.
For each bar chart, we set the x ticks lables with the color value, and set the title with the style name.
use tight_layout()
to make the layout more beautiful.
In [6]:
blog comments powered by Disqus