matplotlib legend background color

user1850133

Is there while rcParams['legend.frameon'] = 'False' a simple way to fill the legend area background with a given colour. More specifically I would like the grid not to be seen on the legend area because it disturbs the text reading.

The keyword framealpha sounds like what I need but it doesn't change anything.

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['legend.frameon'] = 'False'
plt.plot(range(5), label = u"line")
plt.grid(True)
plt.legend(loc = best)
plt.show()

I've also tried:

legend = plt.legend(frameon = 1)
frame = legend.get_frame()
frame.set_color('white')

but then I need to ask how can I change the background colour while keeping the frame on? Sometimes I want it ON with a background colour other than white. And also, is there a way of changing the colour of the frame? With the above code I was expecting to change the colour of the frame only, not the background.

Molly

You can set the edge color and the face color separately like this:

frame.set_facecolor('green')
frame.set_edgecolor('red')

There's more information under FancyBboxPatch here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Matplotlib: combine legend with same color and name

From Dev

matplotlib get errorbar color from legend

From Dev

Matplotlib: combine legend with same color and name

From Dev

matplotlib plotting legend corresponding to size and color of points

From Dev

matplotlib conditional background color in python

From Dev

Need to apply background color to each legend text highchart

From Dev

ggplot2: Change color of background for geom_vline legend

From Dev

Change default background color for matplotlib plots

From Dev

mollview: use matplotlib colormaps and change background color

From Dev

matplotlib.pyplot scatterplot legend from color dictionary

From Java

Matplotlib scatter plot color-coded by text, how to add legend?

From Dev

Matplotlib Legend with Different Number and Color of Markers per Handle

From Dev

Legend in matplotlib

From Dev

Matplotlib figure facecolor alpha while saving (background color, transparency)

From Dev

Matplotlib: change background color of colorbar (when using transparent colors)

From Dev

ggplot2: how to assign a graduated color legend and add shaded relief background to a map

From Dev

Why can't I change the background color of a ggplot legend box to white? (Other colors work fine)

From Dev

ggplot2: how to assign a graduated color legend and add shaded relief background to a map

From Dev

Matplotlib scatter plot with legend

From Dev

Matplotlib legend for an arrow

From Dev

Matplotlib legend fontsize

From Dev

tabular legend layout for matplotlib

From Dev

Matplotlib Stackplot legend Error

From Java

Matplotlib scatter plot legend

From Dev

Duplicate items in legend in matplotlib?

From Dev

Shade legend line in matplotlib

From Dev

legend alignment in matplotlib

From Dev

Multiple titles in legend in matplotlib

From Dev

Align legend rows in matplotlib

Related Related

  1. 1

    Matplotlib: combine legend with same color and name

  2. 2

    matplotlib get errorbar color from legend

  3. 3

    Matplotlib: combine legend with same color and name

  4. 4

    matplotlib plotting legend corresponding to size and color of points

  5. 5

    matplotlib conditional background color in python

  6. 6

    Need to apply background color to each legend text highchart

  7. 7

    ggplot2: Change color of background for geom_vline legend

  8. 8

    Change default background color for matplotlib plots

  9. 9

    mollview: use matplotlib colormaps and change background color

  10. 10

    matplotlib.pyplot scatterplot legend from color dictionary

  11. 11

    Matplotlib scatter plot color-coded by text, how to add legend?

  12. 12

    Matplotlib Legend with Different Number and Color of Markers per Handle

  13. 13

    Legend in matplotlib

  14. 14

    Matplotlib figure facecolor alpha while saving (background color, transparency)

  15. 15

    Matplotlib: change background color of colorbar (when using transparent colors)

  16. 16

    ggplot2: how to assign a graduated color legend and add shaded relief background to a map

  17. 17

    Why can't I change the background color of a ggplot legend box to white? (Other colors work fine)

  18. 18

    ggplot2: how to assign a graduated color legend and add shaded relief background to a map

  19. 19

    Matplotlib scatter plot with legend

  20. 20

    Matplotlib legend for an arrow

  21. 21

    Matplotlib legend fontsize

  22. 22

    tabular legend layout for matplotlib

  23. 23

    Matplotlib Stackplot legend Error

  24. 24

    Matplotlib scatter plot legend

  25. 25

    Duplicate items in legend in matplotlib?

  26. 26

    Shade legend line in matplotlib

  27. 27

    legend alignment in matplotlib

  28. 28

    Multiple titles in legend in matplotlib

  29. 29

    Align legend rows in matplotlib

HotTag

Archive