9

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

1
  • Note! for 3D you can use ax.xaxis.pane.fill = False or set color of the pane Commented Sep 26, 2023 at 21:19

2 Answers 2

9

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')
Sign up to request clarification or add additional context in comments.

1 Comment

The example given by @Fábio shows that you can use the bgcolor keyword argument of the add_subplot method to achieve the same effect.
6

Is this what you want?

enter image description here

#!/usr/bin/env python
"""
matplotlib gives you 4 ways to specify colors,

    1) as a single letter string, ala MATLAB

    2) as an html style hex string or html color name

    3) as an R,G,B tuple, where R,G,B, range from 0-1

    4) as a string representing a floating point number
       from 0 to 1, corresponding to shades of gray.

See help(colors) for more info.
"""
from pylab import *

subplot(111, axisbg='darkslategray')
#subplot(111, axisbg='#ababab')
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s, 'y')
xlabel('time (s)', color='r')
ylabel('voltage (mV)', color='0.5') # grayscale color
title('About as silly as it gets, folks', color='#afeeee')
show()

1 Comment

Just to update this a little, the axisbg argument has been deprecated and replaced with facecolor.

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.