legend

matplotlib legend: Including markers and lines from two different graphs in one line

我只是一个虾纸丫 提交于 2019-11-28 07:52:51
问题 I've been doing some linear regression and want to plot the markers (original data) and the lines (regression) on the same line in the legend. For simplicity, here's a fake regression: from pylab import * ax = subplot(1,1,1) p1, = ax.plot([1,2,3,4,5,6],'r-', label="line 1") p2, = ax.plot([6,5,4,3,2,1],'b-', label="line 2") p3, = ax.plot([1.2,1.8,3.1,4.1,4.8,5.9],'ro', label="dots 1") p4, = ax.plot([6.1,5.1,3.8,3.1,1.9,0.9],'bo', label="dots 2") ax.legend(loc='center right',numpoints=1) show()

How to move or position a legend in ggplot2

别来无恙 提交于 2019-11-28 07:07:36
I'm trying to create a ggplot2 plot with the legend beneath the plot. The ggplot2 book says on p 112 "The position and justification of legends are controlled by the theme setting legend.position, and the value can be right, left, top, bottom, none (no legend), or a numeric position". The following code works (since "right" it is the default), and it also works with "none" as the legend position, but "left", "top", "bottom", all fail with "Error in grid.Call.graphics("L_setviewport", pvp, TRUE) : Non-finite location and/or size for viewport" library(ggplot2) (myDat <- data.frame(cbind(VarX=10

ggplot legend issue w/ geom_point and geom_text

时光毁灭记忆、已成空白 提交于 2019-11-28 06:56:39
I am trying to use geom_point to illustrate the count of my data. I would also like to annotate a few of the points in my graph with geom_text . When I add the call to geom_text , it appears that it is plotting something underneath the points in the legend. I've tried reversing the order of the layers to no avail. I can't wrap my head around why it is doing this. Has anyone seen this before? set.seed(42) df <- data.frame(x = 1:10 , y = 1:10 , label = sample(LETTERS,10, replace = TRUE) , count = sample(1:300, 10, replace = FALSE) ) p <- ggplot(data = df, aes(x = x, y = y, size = count)) + geom

Setting a fixed size for points in legend

十年热恋 提交于 2019-11-28 06:48:04
I'm making some scatter plots and I want to set the size of the points in the legend to a fixed, equal value. Right now I have this: import matplotlib.pyplot as plt import numpy as np def rand_data(): return np.random.uniform(low=0., high=1., size=(100,)) # Generate data. x1, y1 = [rand_data() for i in range(2)] x2, y2 = [rand_data() for i in range(2)] plt.figure() plt.scatter(x1, y1, marker='o', label='first', s=20., c='b') plt.scatter(x2, y2, marker='o', label='second', s=35., c='r') # Plot legend. plt.legend(loc="lower left", markerscale=2., scatterpoints=1, fontsize=10) plt.show() which

ggplot2: Different legend symbols for points and lines

情到浓时终转凉″ 提交于 2019-11-28 06:28:35
already searched all related threads about this but could not find a solution. Here is my code and the attached plot result: g <-ggplot(NDVI2, aes(LAI2, NDVI, colour = Legend)) + theme_bw (base_family = "Times") + scale_colour_manual (values = c("purple", "green", "blue", "yellow", "magenta","orange", "cyan", "red", "black")) + geom_point (size = 3) + geom_smooth (aes(group = 1, colour = "Trendline"), method = "loess", size = 1, linetype = 5, se = FALSE) + geom_smooth (aes(group = 1, colour = "Regression (log)"),linetype = 1, size=1.2,method = "lm", formula = y~ log(x), se = FALSE) + labs

Legend outside plot does not work with plotyy in Octave

吃可爱长大的小学妹 提交于 2019-11-28 06:11:42
问题 I am trying to create a plot in Octave (using v4.4.1 on Windows) using plotyy and putting the legend outside the plot (because the data covers all the usable space inside the graph). The following MVCE should reproduce the issue fairly well: % Generate some random data to reproduce the issue data = rand(1000,10); data(:,1:8) = data(:,1:8)-0.5; data(:,9:10) = data(:,9:10)+30; timedate = linspace(737310,737313,size(data,1)); data_labels={'1';'2';'3';'4';'5';'6';'7';'8';'9';'10'}; % Plot the

ggplot legend - scale_colour_manual not working

只愿长相守 提交于 2019-11-28 05:18:52
问题 I am trying to add a legend to my graphs, but nothing ever shows up. This is the code I have: ggplot(main, aes(x = ceiling(session/2))) + geom_line(aes(y = C_overall), colour = "blue", stat = "summary", fun.y = "mean") + geom_line(aes(y = I_overall), colour = "red", stat = "summary", fun.y = "mean") + labs(title = 'Overall Accuracy', x = 'Session', y = 'Percent Accurate') + facet_wrap(~bird) This shows me what I want, except with no legend. Everything I've seen says to use scale_colour_manual

Legend on bottom, two rows wrapped in ggplot2 in r

醉酒当歌 提交于 2019-11-28 05:13:00
Rdates <- c("2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29","2007-07-31","2007-08-31","2007-09-28","2007-10-31") Rdates <- as.Date(Rdates) Cnames <- c("Column 1 Really Long","Column 2 Really Long","Column 3 Really Long","Column 4 Really Long","Column 5 Really Long","Column 6 Really Long","Column 7 Really Long","Column 8 Really Long","Column 9 Really Long","Column 10 Really Long") MAINDF <- data.frame(replicate(10,runif(10,-0.03,0.03))) rownames(MAINDF) <- Rdates colnames(MAINDF) <- Cnames CUSTOMpalette <- c("#1a2ffa", "#0d177d", "#1a9ffa", "#fa751a", "#4b8e12", "

How to set font size of Matplotlib axis Legend?

前提是你 提交于 2019-11-28 04:28:45
I have a code like this: import matplotlib.pyplot as plt from matplotlib.pyplot import * from matplotlib.font_manager import FontProperties fontP = FontProperties() fontP.set_size('xx-small') fig=plt.figure() ax1=fig.add_subplot(111) plot([1,2,3], label="test1") ax1.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1, 1), prop = fontP,fancybox=True,shadow=False,title='LEGEND') plt.show() It can be seen in the plot that the setting in Fontsize does not affect the Legend Title font size. How to set the font size of the legend title to a smaller size? This is definitely an old question, but was

R legend placement in a plot

牧云@^-^@ 提交于 2019-11-28 03:57:36
I have a plot that has data that runs into the area I'd like to use for a legend. Is there a way to have the plot automatically put in something like a header space above the highest data points to fit the legend into? I can get it to work if I manually enter the ylim() arguments to expand the size and then give the exact coordinates of where I want the legend located, but I'd prefer to have a more flexible means of doing this as it's a front end for a data base query and the data levels could have very different levels. Edit 2017: use ggplot and theme(legend.position = ""): library(ggplot2)