Colorbars for mixed usage of colormaps and static colors

In case you want to show colormapped data with matplotlib and you use code similar to this one:

you will get the following error.

This is because the colorbar method draws the last colormap used, which is given as a None default argument to plt.scatter. Therefore, making the calls to plt.scatter in the order given in the example above overwrites the colorbar value internally at sets it to None, which gives the error mentioned above. Make sure that the last plt.anything function is called with an appropriate cmap argument just before you add the plt.colorbar.

Leave a comment

Your email address will not be published.