Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib changing line color with rcParams

I just learned about the matplotlib.rcParams feature and so I tried to plot a very simple graph.

import matplotlib.pyplot as plt

x = [1,2,3,4,5]
y = [5,3,7,9,2]

plt.rcParams['lines.color'] = 'r'
plt.rcParams['lines.linewidth'] = 3.0

plt.plot(x, y)
plt.show()

The resulting plot has increased linewidth but the color remains unchanged. The line is still blue. When I check the plt.rcParams['lines.color'] value, it prints 'r'. I'm using matplotlib version 1.3.1 with 32-bit Python 2.7.6.

Am I doing something wrong ?

like image 486
zerovar Avatar asked May 07 '26 20:05

zerovar


2 Answers

Starting from matplotlib 1.5, mpl.rcParams['axes.color_cycle'] is deprecated. You should use axes.prop_cycle:

import matplotlib as mpl
mpl.rcParams['axes.prop_cycle'] = mpl.cycler(color=["r", "#e94cdc", "0.7"]) 
like image 125
user9026 Avatar answered May 09 '26 09:05

user9026


As mentioned in http://matplotlib.org/users/customizing.html , it has no affect on plot()

# lines.color : blue # has no affect on plot(); see axes.color_cycle

Instead, this works:

plt.rcParams['axes.color_cycle']='r'
plt.rcParams['lines.linewidth'] = 3.0

plt.plot(x, y)
plt.show()
like image 28
giosans Avatar answered May 09 '26 11:05

giosans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!