0

This article How to set the default color cycle for all subplots with matplotlib? teaches us how to use mpl.rcParams['axes.color_cycle'] = ['r', 'k', 'c'] to change the default colour 'r', 'k', 'c' cycle to red, black and cyan. However, how can I change the actual hex-triplets which 'r', 'k', 'c' represent? Say I want 'r' to represent #8F00FF (violet)? Or even better, how can I add colours, such that 'v' represent the hex-triplet #8F00FF? I hope to use them to implement them in mpl.rcParams['axes.color_cycle'].

0

1 Answer 1

2

You can specify the colors using hex notation directly in for the color cycle, like this:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from cycler import cycler # for mpl>2.2

mpl.rcParams['axes.prop_cycle'] = cycler(color=['r', '#8F00FF', '#A0F0A0'])

# for mpl < 2.2
#mpl.rcParams['axes.color_cycle'] = ['r', '#8F00FF', '#A0F0A0']

y = np.arange(5)
for i in range(7):
    plt.plot(y + i, linewidth=5)

plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Not working. axes.color_cycle is not a valid rc parameter. I used: from cycler import cycler and mpl.rcParams['axes.prop_cycle'] = cycler(color=['#2EBCE7', '#84EE29', '#FF8177'])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.