legend

Matplotlib savefig with a legend outside the plot

我的未来我决定 提交于 2019-11-27 21:02:39
Reading the following article, I managed to put a legend outside plot. How to put the legend out of the plot code: import matplotlib.pyplot as pyplot x = [0, 1, 2, 3, 4] y = [xx*xx for xx in x] fig = pyplot.figure() ax = fig.add_subplot(111) box = ax.get_position() ax.set_position([box.x0, box.y0, box.width*0.8, box.height]) ax.plot(x, y) leg = ax.legend(['abc'], loc = 'center left', bbox_to_anchor = (1.0, 0.5)) #pyplot.show() fig.savefig('aaa.png', bbox_inches='tight') pyplot.show() displays the correct plot with a legend outside it. But when I save it as a file with fig.savefig() , the

Legend of a raster map with categorical data

与世无争的帅哥 提交于 2019-11-27 20:16:37
I would like to plot a raster containing 4 different values ( 1 ) with a categorical text legend describing the categories such as 2 but with colour boxes: I've tried using legend such as : legend( 1,-20,legend = c("land","ocean/lake", "rivers","water bodies")) but I don't know how to associate one value to the displayed color. Is there a way to retrieve the colour displayed with 'plot' and to use it in the legend? The rasterVis package includes a Raster method for levelplot() , which plots categorical variables, and produces an appropriate legend: library(raster) library(rasterVis) ## Example

Dynamic Legend (Updates in every recursion)

点点圈 提交于 2019-11-27 19:32:52
I got a for i=1:15 . Inside I generate a variable d=1:0.01:10 , which is the x'x axis and based on this, I create a continuous function F(d) which has 2 unique variables pitch and yaw. I then plot this using different colors in every recursion using cmap = hsv(15); . So then it is: d=1:0.01:10; cmap = hsv(15); for i=1:15 pitch = unidrnd(10); yaw = unidrnd(10); for j=1:length(d) F(j) = d(j)*3*pitch*yaw; %// some long calculation here end p1 = plot(d,F,'Linewidth', 1.0); title ('blah blah') set(p1, 'Color', cmap(i,:)); hold on; legend (['pitch,yaw:', num2str(pitch) num2str(yaw)]) end hold off;

independently move 2 legends ggplot2 on a map

。_饼干妹妹 提交于 2019-11-27 18:46:40
问题 I want to independently move two legends on a map to save save and make the presentation nicer. Here is the data: ## INST..SUB.TYPE.DESCRIPTION Enrollment lat lng ## 1 CHARTER SCHOOL 274 42.66439 -73.76993 ## 2 PUBLIC SCHOOL CENTRAL 525 42.62502 -74.13756 ## 3 PUBLIC SCHOOL CENTRAL HIGH SCHOOL NA 40.67473 -73.69987 ## 4 PUBLIC SCHOOL CITY 328 42.68278 -73.80083 ## 5 PUBLIC SCHOOL CITY CENTRAL 288 42.15746 -78.74158 ## 6 PUBLIC SCHOOL COMMON NA 43.73225 -74.73682 ## 7 PUBLIC SCHOOL INDEPENDENT

How to show legend for only a specific subset of curves in the plotting?

橙三吉。 提交于 2019-11-27 18:29:42
t = 0 : 0.01 : 2 * pi; s = sin(t); c = cos(t); m = -sin(t); hold on; plot(t, s, 'r'); plot(t, c, 'b'); plot(t, m, 'g'); hold off; legend('', 'cosine', ''); There are several curves in my plotting. I want to display legend for only some of them. How do I do it? For example, how do I make only the legend for the cosine curve visible in the plotting above? When I call the legend() functions as legend('', 'cosine'); instead of adding the empty third parameter, indeed the third green line is removed from the legend. But that doesn't solve my problem, because the undesired red line stays visible.

increase the linewidth of the legend lines in matplotlib

心不动则不痛 提交于 2019-11-27 18:28:12
I know that if I change the linewidth of a line, that is automatically updated in the legend. However I would like to just change the legend linewidth without affecting the plot. Brendan Wood Here's a simple example of how to do it: import numpy as np import matplotlib.pyplot as plt # make some data x = np.linspace(0, 2*np.pi) y1 = np.sin(x) y2 = np.cos(x) # plot sin(x) and cos(x) p1 = plt.plot(x, y1, 'b-', linewidth=1.0) p2 = plt.plot(x, y2, 'r-', linewidth=1.0) # make a legend for both plots leg = plt.legend([p1, p2], ['sin(x)', 'cos(x)'], loc=1) # set the linewidth of each legend object for

Change Silverlight Chart Legend Item Layout

谁都会走 提交于 2019-11-27 18:08:58
问题 I am working on customizing the layout of a Silverlight Toolkit Chart. I have two requirements: 1) Move the Legend area to the bottom of the chart (solved). 2) change the layout of elements within the legend to be displayed next to each other, ie. {legend 1},{legend 2},{legend 3}, rather than the default column format. 1) was easy to solve with a ControlTemplate (see below). 2) How do I change the layout of legend items? Can it be done by further customizing the Chart's ControlTemplate, or

matplotlib: colorbars and its text labels

穿精又带淫゛_ 提交于 2019-11-27 17:25:53
I'd like to create a colorbar legend for a heatmap , such that the labels are in the center of each discrete color. Example borrowed from here : import matplotlib.pyplot as plt import numpy as np from matplotlib.colors import ListedColormap #discrete color scheme cMap = ListedColormap(['white', 'green', 'blue','red']) #data np.random.seed(42) data = np.random.rand(4, 4) fig, ax = plt.subplots() heatmap = ax.pcolor(data, cmap=cMap) #legend cbar = plt.colorbar(heatmap) cbar.ax.set_yticklabels(['0','1','2','>3']) cbar.set_label('# of contacts', rotation=270) # put the major ticks at the middle of

Remove the legend on a matplotlib figure

走远了吗. 提交于 2019-11-27 17:21:51
To add a legend to a matplotlib plot, one simply runs legend() . How to remove a legend from a plot? (The closest I came to this is to run legend([]) in order to empty the legend from data. But that leaves an ugly white rectangle in the upper right corner.) As of matplotlib v1.4.0rc4 , a remove method has been added to the legend object. Usage: ax.get_legend().remove() or legend = ax.legend(...) ... legend.remove() See here for the commit where this was introduced. ERN You could use the legend's set_visible method: ax.legend().set_visible(False) draw() This is based on a answer provided to me

Change geom_text's default “a” legend to label string itself

我的梦境 提交于 2019-11-27 16:02:16
问题 Similarly to this question, I want to change the default "a" in the legend, but rather than removing it completely, I want to replace it with the labels themselves. That is, the first line of the legend should have a colored icon labeled "se" with the full name "setosa" on the right. iris$abbrev = substr( iris$Species, 1, 2 ) ggplot(data = iris, aes(x = Sepal.Length, y=Sepal.Width, shape = Species, colour = Species)) + geom_text(aes(label = abbrev)) 回答1: You can change the legend key