Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opaque Legend Box

I was wondering how I could go about creating an opaque legend box in R for my plots? I've tried using bg="grey", but the lines on the graph are still covering the legend.

like image 764
MikeZ Avatar asked Jun 19 '12 20:06

MikeZ


People also ask

How do you make a legend transparent in Matlab?

Note that making legends fully-transparent is easy in either HG1 or HG2: simply set the legend's Color property to 'none' .

What is PLT legend ()?

The simplest legend can be created with the plt.legend() command, which automatically creates a legend for any labeled plot elements: import matplotlib.pyplot as plt plt. style. use('classic') %matplotlib inline import numpy as np.

Which argument must be set with plotting function for Legend () to display the legends?

Which argument must be set with plotting function for Legend () to display the legends? Arguments. the x and y co-ordinates to be used to position the legend. They can be specified by keyword or in any way which is accepted by xy.

How do you show the legend outside the plot in Python?

In the Matplotlib library, there's a function called legend() which is used to Place a legend on the axes. The attribute Loc in legend() is used to specify the location of the legend. The default value of loc is loc= “best” (upper left).


1 Answers

You have to use bg="white" (or any other color, as you already did) and you have to draw the legend after you plot the lines/points/grid/etc.

For example:

plot(...)
lines(...)
grid(...)
legend(...) # legend has to be the last command!
like image 67
timos Avatar answered Oct 01 '22 08:10

timos