Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the face color of a plot using Matplotlib

I just started using Matplotlib and am trying to change the color of the face color of a plot...

if I create the figure like this:

 plt.figure(num=None, figsize=(5, 10), dpi=80, facecolor='y', edgecolor='k')

only the boarder of the figure changes to yellow... What I would like is the boarder to be white and the plot to be yellow..

edit:

A snip from my current code:

plt.figure(num=None, figsize=(5, 10), dpi=80, facecolor='y', edgecolor='k')  

ax = plt.gca()

ax.plot(x, y, color = 'g')

enter image description here

like image 894
Richard Avatar asked Mar 03 '11 14:03

Richard


People also ask

How do I specify colors on a matplotlib plot?

The usual way to set the line color in matplotlib is to specify it in the plot command. This can either be done by a string after the data, e.g. "r-" for a red line, or by explicitely stating the color argument.

How do I change the color of my plot area in Python?

You can pass the color parameter to change the color of the area and the alpha parameter to change the color transparancy of the area to the fill_between() function. You can also add a line with the plot() function and change its color to make the edge of the area marked.

How do I shade part of a plot in matplotlib?

Plot x and y data points, with color=red and linewidth=2. To shade an area parallel to X-axis, initialize two variables, y1 and y2. To add horizontal span across the axes, use axhspan() method with y1, y2, green as shade color,and alpha for transprency of the shade. To display the figure, use show() method.

How do I change the background color in matplotlib?

To change the axes background color, we can use set_facecolor() method.


1 Answers

Hm, you could try set_axis_bgcolor. Also, instead of using gca, try this, it's cleaner:

fig = plt.figure(num=None, figsize=(5, 10), dpi=80, facecolor='y', edgecolor='k')
ax = fig.add_subplot(111)
ax.set_axis_bgcolor("y")
ax.plot(x, y, color = 'g')
like image 99
Björn Pollex Avatar answered Oct 16 '22 06:10

Björn Pollex