Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set default Matplotlib axis colour cycle

Tags:

matplotlib

The default axis colour cycle in Matplotlib 2.0 is called tab10:

enter image description here

I want to use a different qualitative colour cycle, such as tab20c:

enter image description here

I have used this code to change the default axis colour cycle:

import matplotlib.pyplot as plt
from cycler import cycler

c = plt.get_cmap('tab20c').colors
plt.rcParams['axes.prop_cycle'] = cycler(color=c)

This looks pretty dirty to me. Is there a better way?

like image 792
onewhaleid Avatar asked Sep 11 '17 04:09

onewhaleid


People also ask

What is the default color cycle matplotlib?

The default interactive figure background color has changed from grey to white, which matches the default background color used when saving. in your matplotlibrc file.

How do I set the default style in matplotlib?

plt. style. use('default') worked for me. As I understand this, it tells matplotlib to switch back to its default style mode.

What is the default blue matplotlib?

The default color of a scatter point is blue. To get the default blue color of matplotlib scatter point, we can annotate them using annotate() method.


1 Answers

As said in the comments, it's not clear what "better" would mean. So I can think of two different ways in addition to the one from the question, which works perfectly fine.

(a) use seaborn

Just to show a different way of setting the color cycler: Seaborn has a function set_palette, which does essentially set the matplotlib color cycle. You could use it like

import matplotlib.pyplot as plt
import seaborn as sns
sns.set_palette("tab20c",plt.cm.tab20c.N )

(b) set the cycler for the axes only

If you want the cycler for each axes individually, you may use ax.set_prop_cycle for an axes ax.

import matplotlib.pyplot as plt
from cycler import cycler

fig, ax = plt.subplots()
ax.set_prop_cycle(cycler(color=plt.get_cmap('tab20c').color‌‌​​s))
like image 105
ImportanceOfBeingErnest Avatar answered Nov 16 '22 07:11

ImportanceOfBeingErnest