legend

How to switch between multiple map legends with leaflet.js?

笑着哭i 提交于 2019-12-08 12:18:16
问题 I`m using leaflet.js library to create multiple maps based on statistical data. Each map displays different range of values so it would be nice to change legend when user change map. I found similar example in this question, but I need to switch between more than two layers. I try simply add more "if" statments and logical operators in code, but it doesn`t work right: map.on('baselayerchange', function (eventLayer) { if (eventLayer.name === 'Agricultural') { map.removeControl(VODlegend ||

Positioning legend on plot divided by par(mfrow) in R

﹥>﹥吖頭↗ 提交于 2019-12-08 11:19:28
问题 I have my plot window divided using par(mfrow=c(2,4)) I have 7 plots and would like to use the remaining plot space to write the legend (i.e. the blank space in the bottom right hand corner) I was wondering is there an easy way to put the legend into this position? pdf("Plot") par(mfrow=c(2,4), lwd=2, font=2, font.lab=2, font.axis=2, oma=c(0,0,2,0)) for(i in 1:7){ image(imagearray[,,i], axes=F, col=grey(c(0:225)/225), main= paste("Plot",i)) title("Plot", outer=T) } dev.off() 回答1: You dont

How to render a plotly plot with preset traces hidden i.e. 'legendonly' based on list

走远了吗. 提交于 2019-12-08 10:45:10
问题 Thanks to help on a previous question here I can now record in a list which traces are hidden in a plotly plot by reading out the legend list of TRUE/legendonly with a piece of javascript , which I use to change the list entries, and the color of associated buttons. What I'm now also looking to do, is to maintain that TRUE/legendonly status when the plot is re-rendered. In the dummy app below, the plot can be re-rendered with the switch actionbutton , which causes a re- render due to a change

bokeh add legend to Step graph

允我心安 提交于 2019-12-08 09:10:14
问题 How can I add a legend to lines in Step graph example for bokeh: https://docs.bokeh.org/en/latest/docs/reference/models/glyphs/step.html I would like to have legend in 'top right' corner of plot for each line in color and style of the line. The default code for the example is: import numpy as np from bokeh.models import ColumnDataSource, DataRange1d, Plot, LinearAxis, Grid from bokeh.models.glyphs import Step from bokeh.io import curdoc, show N = 11 x = np.linspace(-2, 2, N) y = x**2 source =

Contour plot legend - Matplotlib

℡╲_俬逩灬. 提交于 2019-12-08 06:42:22
问题 As the question says, I have a contour plot and I would like show a legend for if. I'm using the contour plot style that uses: dashed lines for negative levels solid lines for positive values I would like to have a legend for them (dashed == negative and solid == positive). I tried the approaches found here and here. However, as can be seen below, this doesn't show the correct result. # Draw the scalar field level curves div_field = plt.contour(x, y, div_scalar_field, colors='white') rot

How to add multiple legend titles (columns) in ggplot

无人久伴 提交于 2019-12-08 05:24:53
问题 In the stacked bar chart, I have different colors for treatment group and control group. Green for control group and blue for treatment group. In the legend part, I want to show two columns of legends, one for each group. My code is shown below: ID<-c(rep(1:4, 6)) Group<-c(rep(0,4), rep(1,4), rep(0,4), rep(1,4), rep(0,4), rep(1,4)) Time<-c(rep("Time 1",8), rep("Time 2",8), rep("Time 3",8)) Response<-c(1,2,3,1,2,3,1,2,2,3,3,1,1,3,2,1,2,1,3,1,2,2,1,3) data <- data.frame(ID, Group, Time,

Legend based on edge color in networkx

微笑、不失礼 提交于 2019-12-08 05:13:39
问题 Is there a way to create a legend in networkx based on edge color (as opposed to by node color)? This is my graph: plt.figure(figsize = (15, 10)) G = nx.from_pandas_dataframe(df, 'From', 'To', ['Order', 'Colors']) edge_labels = nx.get_edge_attributes(G, 'Order') nx.draw_networkx(G, with_labels = False, node_color = 'black', alpha = 0.5, node_size = 3, linewidths = 1, edge_color = df['Colors'], edge_cmap = plt.cm.Set2) plt.show() In this, ['Order'] is a descriptor of the edge and ['Color'] is

Leaflet add/remove legends with layer selection

僤鯓⒐⒋嵵緔 提交于 2019-12-08 02:32:20
问题 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

R how to control spacing of colour bar/legend

 ̄綄美尐妖づ 提交于 2019-12-08 02:27:12
问题 I'd like to plot a map of chlorophyll concentration, but the values are dispersed in such a way that the legend becomes unreadable (see picture) So I am trying to control the spacing of the colours in the colour bar/legend. I'd like to get it evenly spaced (while keeping the uneven breaks on the map itself). The the example below is much simplified and is for a raster plot, but the same goes for image.plot. library(raster) r <- raster(ncol=5, nrow=4) r[] <- 1:20 plot(r, breaks = c(0,1,2,3,5

Change the size of the text in legend according to the length of the legend vector in the graph

我的未来我决定 提交于 2019-12-08 02:21:54
问题 I have to draw a 20 plots and horizontally place a legends in each plots. I gave the following command for the first plot: plot(x=1:4,y=1:4) legend("bottom",legend = c("a","b","c","d"),horiz=TRUE,text.font=2,cex=0.64) then for the second plot I tried : plot(x=1:2,y=1:2) legend("bottom",legend = c("a","b"),horiz=TRUE,text.font=2,cex=0.64) But because the size of the character vector passed to legend argument are different I get the size of the legend different. Since I have to plot so many