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')
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.
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.
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.
To change the axes background color, we can use set_facecolor() method.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With