legend

Issue with Matplotlib scatterplot and Color maps

牧云@^-^@ 提交于 2019-12-10 14:53:26
问题 I am working on a project that involves applying colormaps to scatterplots generated in matplotlib. My code works as expected, unless the scatterplot being generated has exactly four points. This is illustrated in the following code: import numpy as np import matplotlib.pyplot as plt cmap = plt.get_cmap('rainbow_r') z = np.arange(20) plt.close() plt.figure(figsize=[8,6]) for i in range(1,11): x = np.arange(i) y = np.zeros(i) + i plt.scatter(x, y, c=cmap(i / 10), edgecolor='k', label=i, s=200)

Why does the ggplot legend show the “colour” parameter?

主宰稳场 提交于 2019-12-10 13:46:42
问题 I have the following example: data <- structure(list(a = c(-1.25549186262767, -0.840855480786298, - 0.635371312524283, -0.602907981454667, -0.472166385166945, -0.285773634866154, 0.0701427664273268, 0.138108224803923, 1.38435934347858, 1.71144087270237), b = c(-3.44400412039417, 0.675644682353751, -1.04793816522475, -7.38303347186651, 2.34519166466874, 0.334780748573386, 4.76806919070976, 4.8633533150074, 3.50106026731172, -1.27172351054143), c = c(-3.02376206439776, -2.56390769080574, -1

Removing ggplot legend symbol while retaining label

ぃ、小莉子 提交于 2019-12-10 12:43:26
问题 Example code and figure: data <- data.frame( ID = c(LETTERS[1:26], paste0("A",LETTERS[1:26])), Group = rep(c("Control","Treatment"),26), x = rnorm(52,50,20), y = rnorm(52,50,10)) ggplot(data, aes(y=y,x=x, label=ID, color=Group)) + geom_text(size=8) + scale_color_manual(values=c("blue","red")) + theme_classic() + theme(legend.text = element_text(color=c("blue","red"))) What I'm trying to solve is removing the legend symbols (the "a") and coloring the Group labels (Control and Treatment) as

How to make R legend with 2 columns?

允我心安 提交于 2019-12-10 12:38:57
问题 I want to make a legend on my graph, which is generated by plot() function. The original legend() function will generate a list which has only 1 column. How can I make a legend which has 2 columns? 回答1: I could not find a way to do that within a single call to legend for standard plots. Here's an option, drawing two separate legends: one with lines and points, one with labels. x.intersp can be used to tweak distance between labels and lines. plot(cumsum(runif(n = 100))) # draw legend with

Setting numpoints in matplotlib legend does not work

孤人 提交于 2019-12-10 12:33:55
问题 I am trying to have a single data point on a plot legend by following the suggestions here and it does not seem to work: from pylab import scatter import pylab import matplotlib.pyplot as plt fig = plt.figure() ax = plt.gca() ax.scatter(1,2,c = 'blue', marker = 'x') ax.scatter(2,3, c= 'red', marker = 'o') ax.legend(('1','2'), loc = 2, numpoints = 1) plt.show() Am I doing something completely stupid here? Some additional information: In [147]: import matplotlib print matplotlib.__version__ Out

Hide MATLAB legend entries for some graphical objects in plots

穿精又带淫゛_ 提交于 2019-12-10 08:01:49
问题 MATLAB legends list everything in a plot, including guidelines that you have put on a plot. A fudge to get around that is to do *Plot *Add legend *Add guidelines However, MATLAB puts the most recent lines in the front, meaning the guidelines then sit over the displayed data; ugly and distracting. Similar problems occur any time you build up a complicated plot, legend freaks out and grabs everything, and workarounds with plotting order can be ugly Example code: %**** Optional guidelines figure

How to legend a raster using directly the raster attribute table and displaying the legend only for class displayed in the raster?

孤街浪徒 提交于 2019-12-10 05:48:02
问题 I would like to use the raster attribute table information to create the legend of a raster such as the raster 1 and display the legend only for the class displayed in the raster. I build an example to explain what I would like to get. 1/ Build the raster r <- raster(ncol=10, nrow=10) values(r) <-sample(1:3,ncell(r),replace=T) 2/ Add the Raster Attribute Table r <- ratify(r) # build the Raster Attibute table rat <- levels(r)[[1]]#get the values of the unique cell frot the attribute table rat

Table legend in matplotlib

拜拜、爱过 提交于 2019-12-10 01:56:37
问题 I would like to make a complex legend in matplotlib. I made the following code import matplotlib.pylab as plt import numpy as np N = 25 y = np.random.randn(N) x = np.arange(N) y2 = np.random.randn(25) # serie A p1a, = plt.plot(x, y, "ro", ms=10, mfc="r", mew=2, mec="r") p1b, = plt.plot(x[:5], y[:5] , "w+", ms=10, mec="w", mew=2) p1c, = plt.plot(x[5:10], y[5:10], "w*", ms=10, mec="w", mew=2) # serie B p2a, = plt.plot(x, y2, "bo", ms=10, mfc="b", mew=2, mec="b") p2b, = plt.plot(x[15:20], y2[15

matplotlib scatter plot with color label and legend specified by c option [duplicate]

南笙酒味 提交于 2019-12-09 19:12:53
问题 This question already has answers here : Matplotlib scatter plot with legend (5 answers) Closed 2 years ago . I'd like to make this kind of scatter plot where the points have colors specified by the "c" option and the legend shows the color's meanings. The data source of mine is like following: scatter_x = [1,2,3,4,5] scatter_y = [5,4,3,2,1] group = [1,3,2,1,3] # each (x,y) belongs to the group 1, 2, or 3. I tried this: plt.scatter(scatter_x, scatter_y, c=group, label=group) plt.legend()

Add NA value to ggplot legend for continuous data map

陌路散爱 提交于 2019-12-09 15:34:49
问题 I'm using ggplot to map data values to a (fortified) SpatialPolygonsDataFrame, but many of the polygons have NA values because there is no data available. I used na.value = "white" to display the missing data correctly, but I'd like to add a box with a white fill in the legend (or a separate legend) with the label "no data". library(ggplot2) india.df <- read.csv('india.df.csv') # (I don't know how to provide this file to make the code reproducible) ggplot() + geom_polygon(data=india.df, aes(x