Matplotlib, the python’s core plotting library, Matplotlib Version 2.2 is available now. The new Matplotlib Version 2.2 has a lot of new things to try including
- A new method to automatically decide spacing between subplots. In the current version, one typically uses tight_layout method to tighten the spaces around plot objects The new method called by constrained_layout=True is hoping to replace tight_layout method.
- Pillow, Python Imaging Library can now be used for creating animations. Pillow can support gif (Pillow>=3.4) output format and webp format (Pillow>=5.0)
- Matplotlib will now support numpy.datetime64 in addition to datetime.datetime. Now you can use numpy.datetime64 anywhere dateime.datetime could be used
- Matplotlib 2.2 has a new color style supporting colorblind-friendly plots. The new style, tableau-colorblind10, offers another colorblind-friendly plot option in addition to the current ‘seaborn-colorblind’ option.
- The new version also has a new dark blue/yellow colormap named ‘cividis’. Cividis colormap is not only colorblind friendly and will also look “effectively identical to colorblind and non-colorblind users”
and many more. Check what’s in new in Matplotlib 2.2, https://matplotlib.org/users/whats_new.html.
Happy to announce Matplotlib 2.2.0!
This is the first release of the 2.2LTS series which will get bug-fixes until 2020.
A big thank you to everyone who worked on this!https://t.co/QUGTrqBMLg
— Matplotlib (@matplotlib) March 7, 2018
You can check your current version of Matplotlib using
import matplotlib matplotlib.__version__
If you are using Anaconda, you can easily upgrade to Matplotlib version 2.2 using
conda update gatplotlib
Let us see examples of using these two new colorblind options in the new Matplotlib version 2.2 using code examples from Matplotlib website.
Cividis: A new Colorblind friendly colormap in Matplotlib 2.2
Let us see the difference between default color map option and the new Cividis colormap that is colorblind friendly.
import matplotlib.pyplot as plt import numpy as np np.random.RandomState(42) fig, ax = plt.subplots() pcm = ax.pcolormesh(np.random.rand(10,10)) fig.colorbar(pcm)
# initialize random seed np.random.RandomState(42) # initialize plot objects fig, ax = plt.subplots() # create a 10x10 matrix with random numbers # and plot heatmap with Cividis colormap pcm = ax.pcolormesh(np.random.rand(10,10),cmap='cividis') # plot colorbar on the side fig.colorbar(pcm)
Tableau Colorblind: A new Colorblind friendly color style in Matplotlib 2.2
Here are some examples comparing the new colorblind-friendly color style, tableau-colorblind10, with the existing colorblind-friendly plot option ‘seaborn-colorblind’ and default color style option. We will be looking at three kind of plots to see the differences, including scatter plots, bar chart and histogram. These plots below were generated by using slightly modified version of Matplotlib’s stylesheet reference code available at https://matplotlib.org/gallery/style_sheets/style_sheets_reference.html.