legend

How to add a string as the artist in matplotlib legend?

核能气质少年 提交于 2019-11-26 17:49:42
问题 I am trying to create a legend in a python figure where the artist is a string (a single letter) which is then labelled. For example I would like a legend for the following figure: import numpy as np import matplotlib.pyplot as plt import string N = 7 x = np.random.rand(N) y = np.random.rand(N) colors = np.random.rand(N) area = np.pi * (15 * np.random.rand(N))**2 plt.scatter(x, y, s=area, c=colors, alpha=0.5) for i,j in enumerate(zip(x,y)): plt.annotate(list(string.ascii_uppercase)[i],xy=j)

Is it possible to define the “mid” range in scale_fill_gradient2()?

房东的猫 提交于 2019-11-26 17:33:45
问题 I am creating a heat map using ggplot() , and would like to utilize the 3 color scheme of scale_fill_gradient2() . I've found, however that the middle color is too broad and tends to display some of my data negatively (using "black" for example). Is it possible to define the range that is considered "mid," to make it more narrow? If not, is there a better way that I may do so? Data Set: structure(list(var1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,

JavaFX Use Chart Legend to toggle show/hide Series possible?

痞子三分冷 提交于 2019-11-26 17:18:04
问题 Is it possible to use a chart's legend to toggle show/hide a series? I got a LineChart with a legend and there are too many Series so you can't read out the information well. I was wondering if there is a possibility to use the legend to toggle the series to show/hide? Most of the names of my Series are pretty long and it looks very weird if they are written twice once in the legend so you know wich color belongs to wich Series and a second time besides a CheckBox to toggle them. Edit1: Maybe

Changing the symbol in the legend key in ggplot2

匆匆过客 提交于 2019-11-26 16:45:57
问题 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)) +

Missing legend with ggplot2 and geom_line

拥有回忆 提交于 2019-11-26 16:38:00
How does one get a legend to display when plotting lines in ggplot? I've been trying all evening but have been unsuccessful. p <- ggplot(output, aes(lambda), legend=TRUE) + geom_line(aes(y=train.err), colour="red", label="r") + geom_line(aes(y=test.err), colour="blue", label="b") + geom_line(aes(y=data.err), colour="green", label="g") print(p) Where output is a dataframe with the following structure: 'data.frame': 2101 obs. of 4 variables: $ lambda : num 3.06e-07 3.09e-07 3.12e-07 3.15e-07 3.18e-07 ... $ train.err: num 0.415 0.415 0.415 0.415 0.415 ... $ test.err : num 0.373 0.373 0.373 0.373

ggplot2 keep unused levels barplot

社会主义新天地 提交于 2019-11-26 16:35:34
I want to plot unused levels (that is, levels where the count is 0) in my bar-plot, however, unused levels are dropped and I cannot figure out how to keep them df <- data.frame(type=c("A", "A", "A", "B", "B"), group=rep("group1", 5)) df$type <- factor(df$type, levels=c("A","B", "C")) ggplot(df, aes(x=group, fill=type)) + geom_bar() In the above example, I want to see C plotted with a count of 0, but it is completely absent... Thanks for any help Ulrik Edit: This does what I want df <- data.frame(type=c("A", "A", "A", "B", "B"), group=rep("group1", 5)) df1 <- data.frame(type=c("A", "A", "A", "B

Matplotlib scatter plot legend

柔情痞子 提交于 2019-11-26 15:59:52
I created a 4D scatter plot graph to represent different temperatures in a specific area. When I create the legend, the legend shows the correct symbol and color but adds a line through it. The code I'm using is: colors=['b', 'c', 'y', 'm', 'r'] lo = plt.Line2D(range(10), range(10), marker='x', color=colors[0]) ll = plt.Line2D(range(10), range(10), marker='o', color=colors[0]) l = plt.Line2D(range(10), range(10), marker='o',color=colors[1]) a = plt.Line2D(range(10), range(10), marker='o',color=colors[2]) h = plt.Line2D(range(10), range(10), marker='o',color=colors[3]) hh = plt.Line2D(range(10)

Remove extra legends in ggplot2

不想你离开。 提交于 2019-11-26 15:59:09
I have a simple data frame that I'm trying to do a combined line and point plot using ggplot2 . Supposing my data looks like this: df <- data.frame(x=rep(1:10,2), y=c(1:10,11:20), group=c(rep("a",10),rep("b",10))) And I'm trying to make a plot: g <- ggplot(df, aes(x=x, y=y, group=group)) g <- g + geom_line(aes(colour=group)) g <- g + geom_point(aes(colour=group, alpha = .8)) g The result looks fine with one exception. It has an extra legend showing the alpha for my geom_point layer. How can I keep the legend showing group colors, but not the one that shows my alpha settings? Aesthetics can be

How do I assign multiple labels at once in matplotlib?

房东的猫 提交于 2019-11-26 15:57:45
问题 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

matplotlib: 2 different legends on same graph

北城余情 提交于 2019-11-26 15:42:31
问题 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