legend

Legend with vertical line in matplotlib

末鹿安然 提交于 2019-12-07 04:12:01
问题 I need to show a vertical line in a matplotlib legend for a specific reason. I am trying to make matplotlib understand that I want a vertical line with the lines.Line2D(x,y) but this is clearly not working. import matplotlib.pyplot as plt from matplotlib import lines fig, ax = plt.subplots() ax.plot([0,0],[0,3]) lgd = [] lgd.append(lines.Line2D([0,0],[0,1], color = 'blue', label = 'Vertical line')) plt.legend(handles = lgd) I need the line to appear vertical, not the legend. Can anyone help?

How to manually change text color of ggplot2 legend in R?

点点圈 提交于 2019-12-07 02:02:50
问题 There might be a simple way to do this, but I am not sure what it is. I am trying to make it so that the text in the legend matches up with the color box next to it. I have been trying to do this for a while and have not found a way to use the element_text function to add multiple colors to the legend. I've had no problem making every label the same color, but is there a way to make each legend label a different color? data<-data.frame(count=c(39,36,19,6), category=c("a","b","c","d")) data

Matplotlib: Multiple legends for contour plot for multiple contour variables

有些话、适合烂在心里 提交于 2019-12-07 01:34:25
I need to make multiple contours plots of several variables on the same page. I can do this with MATLAB (see below for MATLAB code). I cannot get matplotlib to show multiple legends. Any help would be much appreciated. Python code: import numpy as np from matplotlib import cm as cm from matplotlib import pyplot as plt delta = 0.25 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) X, Y = np.meshgrid(x, y) Z1 = X*np.exp(-X**2-Y**2) Z2 = Y*np.exp(-X**2-Y**2) plt.figure() CS = plt.contour(X, Y, Z1, colors='k') plt.clabel(CS, inline=1, fontsize=10) CS = plt.contour(X, Y, Z2, colors='r

Angular ngx-charts options for customizing the Legend?

霸气de小男生 提交于 2019-12-06 23:39:57
问题 I am currently using ngx-charts for Angular2, and I would like to customize some legends, e.g. place the legend below the chart, or rename the legend fields, or make the legend wider (parts of the text just gets cut off..) etc. Are there any good options to customize the legend? Or is it generally not possible, or what is the best way to do it? Currently, my chart legends look like this: Some legends are too wide, some are cut off, and I'd like to position the legend e.g below the chart...

ggplot2: One legend with two visual properties derived from common variable

十年热恋 提交于 2019-12-06 22:12:19
问题 How can I get a single legend that captures both colour and size? I was under the impression that a common legend is default if a common variable is used, but the following example shows I am missing something. library(ggplot2) input <- as.data.frame(matrix(runif(60),nrow=20,ncol=3)) colnames(input) <- c("A","B","C") p <- ggplot(input,aes(A,B,size=C,color=C)) + geom_point() Thanks to Arun for a comment that prompted this edit. So, if one just uses size (and forgets color) one gets a legend

Legend title position in ggplot2

十年热恋 提交于 2019-12-06 20:12:50
问题 Anone know how to change the position of the legend title in ggplot? I have used the following code to move the legend to the bottom and make it horizontal p <- p + opts(legend.position = 'bottom', legend.direction = 'horizontal') But now I want the title to be to the left of the legend instead of above . I've looked in the follwing places but cant find it or figure it out: https://github.com/hadley/ggplot2/wiki/Legend-Attributes http://had.co.nz/ggplot2/book/toolbox.r Any assistance would be

how to align the legend title to the middle of legend box in ggplot2?

跟風遠走 提交于 2019-12-06 19:04:47
问题 I want to move the legend title sex a little right to the horizontal center of legend box. I tried theme and guide_legend but failed. Both ways won't change the legend title position. # example data from http://www.cookbook-r.com/Graphs/Legends_(ggplot2)/ df1 <- data.frame( sex = factor(c("Female","Female","Male","Male")), time = factor(c("Lunch","Dinner","Lunch","Dinner"), levels=c("Lunch","Dinner")), total_bill = c(13.53, 16.81, 16.24, 17.42) ) library(ggplot2) p <- ggplot(data=df1, aes(x

Only display specific labels of a ggplot legend

喜夏-厌秋 提交于 2019-12-06 16:37:59
I have some data points, and I want to single out some of the points in my visualization. I would do it like this: df = data.frame( x = 1:4, y = 1:4, special = c('normal', 'normal', 'normal', 'special') ) ggplot(df) + geom_point(aes(x, y, color = special)) + scale_color_manual(values = c('red', 'black')) + labs(color = "") + theme_bw() My issue here is that the black points are very self explanatory and don't need a label. I want just the red "special" label to appear. Is there a way I can hide the "normal" label? If you are open to having any color other than red: ggplot(df) + geom_point(aes

Leaflet add/remove legends with layer selection

可紊 提交于 2019-12-06 16:00:06
I'm new to Leaflet/JavaScript and have been struggling to get legends a map to show only when a specific layers is selected from the layer control. I have three layers, one of which I would like to have no legend and two others that have a corresponding legend. I came across an example, but have not been able to make it work: // Add and remove legend from layers map.on('overlayadd', function (eventLayer) { // Switch to the Permafrost legend... if (eventLayer.name === 'Permafrost') { this.removeControl(legend1); legend2.addTo(this); } else { // Or switch to the treeline legend... this

Add multiple legends to ggplot2 when using geom_sf

て烟熏妆下的殇ゞ 提交于 2019-12-06 15:54:17
My question combines two separate issues posted on before on Stackoverflow: i. Adding multiple legends to ggplot and ii. Add line legend to geom_sf . I would like to add multiple legends to ggplot2 (as in the first post), but am using sf . This complicates filling up the aesthetic space. The answer suggested in i. above does not work well with multiple types of geometries -- we cannot assign points and lines to a single class and then use factors. In my case, I have several line and point shapefiles, and simply want to add a separate legend entry for each shapefile added. There seems to be no