legend

Subheadings for categories within matplotlib custom legend

折月煮酒 提交于 2019-11-26 11:27:03
问题 I have a a figure that looks like this: I\'d like to make a legend that looks like this: How can I do that? UPDATE: Note that this legend has a frame with an edgecolor: a valid answer will include this. The legend should also be embedded in the axes. The legend I want might not be achievable using ax.legend() . A great answer would be one which shows how to build my desired legend (exactly as shown) manually with patches and texts, or whatever matplotlib methods that make sense. 回答1: Separate

How can I make a fieldset legend-style “background line” on heading text?

匆匆过客 提交于 2019-11-26 09:47:56
问题 I\'m attempting to style heading text similar to how your default legend text appears in fieldsets; that is to say, I\'d like a strikethrough-like line to come up to, but not through, the text. I can\'t seem to find any information on how I might accomplish this, and since on numerous other questions Google\'s always directed me to Stack Overflow for answers, I thought someone here may be able to give me advice. For greater clarity. I\'m attempting to get this effect on header text: Centered

change both legend titles in a ggplot with two legends

旧巷老猫 提交于 2019-11-26 09:28:32
问题 I have two legends on my ggplot with two different legend titles (automatically created from ggplot() ). Now, I want to change this legend titles. + labs(colour = \"legend name\") only change the second legend title. How can I change the first one, too? Sample data: dataset <- structure(list(date = structure(c(1264572000, 1266202800, 1277362800), class = c(\"POSIXt\", \"POSIXct\"), tzone = \"\"), x1 = c(-0.00183760994446658, 0.00089738603087497, 0.000423513598318936), x2 = c(\"approach x\",\

Common legend for multiple plots in R

心不动则不痛 提交于 2019-11-26 09:27:35
问题 I am using R and Latex together to draw some plots and am trying to make a common legend for all of them. I have six separate plots on the same page. I made each plot separately in R and then displayed them on the same page using \\includegraphics in Latex. Each graph has the same legend information, so rather than having a legend in each plot I would like to have one horizontal legend on display at the bottom of page. Unfortunately, I can\'t figure out how to make a legend without a plot.

creating over 20 unique legend colors using matplotlib

≡放荡痞女 提交于 2019-11-26 09:16:42
问题 I am plotting 20 different lines on a single plot using matplotlib. I use a for loop for plotting and label every line with its key and then use the legend function for key in dict.keys(): plot(x,dict[key], label = key) graph.legend() But using this way, the graph repeats a lot of colors in the legend. Is there any way to ensure a unique color is assigned to each line using matplotlib and over 20 lines? thanks 回答1: The answer to your question is related to two other SO questions. The answer

Place a legend for each facet_wrap grid in ggplot2

纵然是瞬间 提交于 2019-11-26 07:31:37
问题 I have this data frame: Date Server FileSystem PercentUsed 1 12/1/2011 A / 60 2 1/2/2012 A /var 50 3 2/1/2012 A tmp 90 4 2/10/2012 A /db 86 5 2/13/2012 A /app 90 6 12/1/2011 B C: 67 7 1/2/2012 B D: 67 8 2/1/2012 B F: 34 9 2/10/2012 B /restore 89 10 2/13/2012 B G: 56 11 12/1/2011 C / 90 12 1/2/2012 C /tmp 78 13 2/1/2012 C /data 67 14 2/10/2012 C /Storage 34 15 2/13/2012 C /database 12 dput(x) structure(list(Date = structure(c(2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L, 2L, 1L, 3L, 4L, 5L), .Label

ggplot separate legend and plot

这一生的挚爱 提交于 2019-11-26 05:37:51
问题 I am using the grid lpackage to place my graphs that I made with ggplot2 : library(ggplot2) library(grid) Layout <- grid.layout(nrow = 4, ncol = 4, widths = unit(1, \"null\"), heights = unit(c(0.4, 0.8, 1.2, 1.2), c(\"null\", \"null\", \"null\"))) grid.show.layout(Layout) plot1 = ggplot(diamonds, aes(clarity, fill = color)) + geom_bar() + facet_wrap(~cut, nrow = 1) print(plot1 + theme(legend.position = \"none\"), vp = viewport(layout.pos.row = 3, layout.pos.col = 1:4)) The problem is that I

Missing legend with ggplot2 and geom_line

瘦欲@ 提交于 2019-11-26 05:36:12
问题 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

ggplot2 keep unused levels barplot

半城伤御伤魂 提交于 2019-11-26 04:51:01
问题 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

How do I position two legends independently in ggplot

久未见 提交于 2019-11-26 04:21:47
问题 Title pretty well covers it. I have two legends, relating to size and colour, and wish to have one,say, on the top and one within the graph. Is this possible and, if so, how TIA 回答1: From my understanding, basically there is very limited control over legends in ggplot2 . Here is a paragraph from the Hadley's book (page 111): ggplot2 tries to use the smallest possible number of legends that accurately conveys the aesthetics used in the plot. It does this by combining legends if a variable is