legend

Creating legend with circles leaflet R

戏子无情 提交于 2019-11-27 14:56:42
问题 I'm trying to create a leaflet map with points sized by a variable. Is it possible to create a legend with different sized circles representing the different variable values? I found another post showing how to convert squares to circles in the legend, but am not sure how to change the size of different circles in the legend. For example, here's a dummy script which creates 10 points associated with 2 classes of a variable (5 and 10). I'd like a legend with two circles the same size as that

Changing the symbol in the legend key in ggplot2

一世执手 提交于 2019-11-27 14:25:41
How do I change the geom_text legend key symbol? In the example below, I'd like to change the symbol in the legend key from a lower case "a" to, say, an upper case "N". I've looked at an example for doing something similar here , but couldn't get that example to work. # Some toy data df <- expand.grid(x = factor(seq(1:5)), y = factor(seq(1:5)), KEEP.OUT.ATTRS = FALSE) df$Count = seq(1:25) # An example plot library(ggplot2) ggplot(data = df, aes( x = x, y = y, label = Count, size = Count)) + geom_text() + scale_size(range = c(2, 10)) EDIT: updating for ggplot version 0.9.2 The original answer

Position the legend outside the plot area with Bokeh

牧云@^-^@ 提交于 2019-11-27 14:13:13
问题 I am making a plot following the example found here Unfortunately, I have 17 curves I need to display, and the legend overlaps them. I know I can create a legend object that can be displayed outside the plot area like here, but I have 17 curves so using a loop is much more convenient. Do you know how to combine both methods? 回答1: Ok, I found the solution. See the code below where I have just modified the interactive legend example: import pandas as pd from bokeh.palettes import Spectral4 from

Leaflet Legend for Custom Markers in R

让人想犯罪 __ 提交于 2019-11-27 14:09:08
I have an R Shiny app that uses Leaflet to create an interactive map. On this map, a categorical variable is used to designate different kinds of points and is visualized using custom markers (different icons, depending on the factor level). What I would like to do is add a legend to the plot, but have the legend show the various marker icons instead of solid colours. The legends tutorial does not cover this. I have come across another SO answer that seems to solve this - but it was done in JavaScript and I'm not sure how to translate it/if it can be translated to work in R. Anyone know how to

Remove line through marker in matplotlib legend

為{幸葍}努か 提交于 2019-11-27 13:55:54
I have a matplotlib plot generated with the following code: import matplotlib.pyplot as pyplot Fig, ax = pyplot.subplots() for i, (mark, color) in enumerate(zip( ['s', 'o', 'D', 'v'], ['r', 'g', 'b', 'purple'])): ax.plot(i+1, i+1, color=color, marker=mark, markerfacecolor='None', markeredgecolor=color, label=i) ax.set_xlim(0,5) ax.set_ylim(0,5) ax.legend() with this as the generated figure: I don't like the lines through the markers in the legend. How can I get rid of them? You can specify linestyle="None" as a keyword argument in the plot command: import matplotlib.pyplot as pyplot Fig, ax =

Matplotlib legend, add items across columns instead of down

旧时模样 提交于 2019-11-27 13:43:09
问题 For a simple plot below, is there a way to make matplotlib populate the legend so that it fills the rows left to right, instead of first column then second column? >>> from pylab import * >>> x = arange(-2*pi, 2*pi, 0.1) >>> plot(x, sin(x), label='Sine') >>> plot(x, cos(x), label='Cosine') >>> plot(x, arctan(x), label='Inverse tan') >>> legend(loc=9,ncol=2) >>> grid('on') 回答1: I can think of one possible way. You can order your legend items as you like. All you need to do is to switch the

How to position and align a matplotlib figure legend?

眉间皱痕 提交于 2019-11-27 13:41:46
问题 I have a figure with two subplots as 2 rows and 1 column. I can add a nice looking figure legend with fig.legend((l1, l2), ['2011', '2012'], loc="lower center", ncol=2, fancybox=True, shadow=True, prop={'size':'small'}) However, this legend is positioned at the center of the figure and not below the center of the axes as I would like to have it. Now, I can obtain my axes coordinates with axbox = ax[1].get_position() and in theory I should be able to position the legend by specifying the loc

How do I assign multiple labels at once in matplotlib?

坚强是说给别人听的谎言 提交于 2019-11-27 12:17:40
I have the following dataset: x = [0, 1, 2, 3, 4] y = [ [0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [9, 8, 7, 6, 5] ] Now I plot it with: import matplotlib.pyplot as plt plt.plot(x, y) However, I want to label the 3 y-datasets with this command, which raises an error when .legend() is called: lineObjects = plt.plot(x, y, label=['foo', 'bar', 'baz']) plt.legend() File "./plot_nmos.py", line 33, in <module> plt.legend() ... AttributeError: 'list' object has no attribute 'startswith' When I inspect the lineObjects : >>> lineObjects[0].get_label() ['foo', 'bar', 'baz'] >>> lineObjects[1].get_label() ['foo',

matplotlib: 2 different legends on same graph

こ雲淡風輕ζ 提交于 2019-11-27 11:45:40
I have a plot where different colors are used for different parameters, and where different line styles are used for different algorithms. The goal is to compare the results of the different algorithms performed with similar parameters. It means in total I use 4 different colors, and 3 different line styles, for a total of 12 plots on the same graph. I actually build the legend based on colors, associating each color with the corresponding parameter. Now I'd like to display a second legend on the same graph, with the meaning of each line style. It is possible to achieve that? How? Here is what

Edit seaborn legend

依然范特西╮ 提交于 2019-11-27 11:31:23
问题 Using a data frame and this code in Python, I was able to create a plot: g = sns.lmplot('credibility', 'percentWatched', data=data, hue = 'millennial', markers = ["+", "."], x_jitter = True, y_jitter = True, size=5) g.set(xlabel = 'Credibility Ranking\n ← Low High →', ylabel = 'Percent of Video Watched [%]') However having the legend say "+ 0" and ". 1" isn't very helpful to readers. How can I edit the legend's labels? Ideally instead of saying 'millennial' it would say 'Generation' and "+