Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

matplotlib styles - setting a legend's background color? #4360

Closed
jclevesque opened this issue Apr 20, 2015 · 2 comments
Closed

matplotlib styles - setting a legend's background color? #4360

jclevesque opened this issue Apr 20, 2015 · 2 comments

Comments

@jclevesque
Copy link
Contributor

Is there a way to change a legend's background color using styles (or equivalently, matplotlib rcParams)?

Say I set the axes background colors to grey, and I want my legend to pop out a bit more. I can set the axes background in my style, but I can't seem to find a way to do it for the legend.

import matplotlib.pyplot as plt
plt.style.use('mystyle')
plt.plot(np.random.sample(10), label='test')
legend = plt.legend()

# how do I automate these two lines
frame = legend.get_frame()
frame.set_facecolor('1')

plt.show()

mystyle.mplstyle :

axes.facecolor: E5E5E5
axes.edgecolor: white
axes.grid: True

xtick.color: 555555
xtick.direction: out

ytick.color: 555555
ytick.direction: out

grid.color: white
grid.linestyle: -    # solid line

figure.facecolor: white
figure.edgecolor: 0.50
@jclevesque
Copy link
Contributor Author

Just found issue #3785

@WeatherGod
Copy link
Member

You are in luck. We have just today merged #4193, which would allow you to
set a value of "inherit" to legend.facecolor and legend.edgecolor.

On Mon, Apr 20, 2015 at 11:43 AM, Julien-Charles Lévesque <
notifications@github.com> wrote:

Is there a way to change a legend's background color using styles (or
equivalently, matplotlib rcParams)?

Say I set the axes background colors to grey, and I want my legend to pop
out a bit more. I can set the axes background in my style, but I can't seem
to find a way to do it for the legend.

import matplotlib.pyplot as plt
plt.style.use('mystyle')
plt.plot(np.random.sample(10), label='test')
legend = plt.legend()

how do I automate these two lines

frame = legend.get_frame()
frame.set_facecolor('1')

plt.show()

mystyle.mplstyle :

axes.facecolor: E5E5E5
axes.edgecolor: white
axes.grid: True

xtick.color: 555555
xtick.direction: out

ytick.color: 555555
ytick.direction: out

grid.color: white
grid.linestyle: - # solid line

figure.facecolor: white
figure.edgecolor: 0.50


Reply to this email directly or view it on GitHub
#4360.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants