legend

pyplot combine multiple line labels in legend

半腔热情 提交于 2019-11-30 05:04:34
I have data that results in multiple lines being plotted, I want to give these lines a single label in my legend. I think this can be better demonstrated using the example below, a = np.array([[ 3.57, 1.76, 7.42, 6.52], [ 1.57, 1.2 , 3.02, 6.88], [ 2.23, 4.86, 5.12, 2.81], [ 4.48, 1.38, 2.14, 0.86], [ 6.68, 1.72, 8.56, 3.23]]) plt.plot(a[:,::2].T, a[:, 1::2].T, 'r', label='data_a') plt.legend(loc='best') As you can see at Out[23] the plot resulted in 5 distinct lines. The resulting plot looks like this Is there any way that I can tell the plot method to avoid multiple labels? I don't want to

Position legend in first plot of facet

让人想犯罪 __ 提交于 2019-11-30 04:24:49
I would like to put my plot legend inside the plot, inside the first plot of a facet. Here is some example code: df=data.frame( x=runif(10), y=runif(10), facet=rep(c("a","b"),5), color=rep(c("red","blue"),5)) ggplot(data=df,aes(x=x,y=y,color=color))+ geom_point()+ facet_wrap(~facet,ncol=1) Here is the resulting plot: And here is roughly how I would like it to look: Thanks for any help you can provide! Richie Cotton Assuming your plot is saved as p p + opts( legend.position = c(0.9, 0.6), # c(0,0) bottom left, c(1,1) top-right. legend.background = theme_rect(fill = "white", colour = NA) ) If

multiple bquote items in legend of an R plot

自作多情 提交于 2019-11-30 02:23:47
问题 Following works, (copy & paste into R) a=123 plot(1,1) legend('bottomleft',legend=bquote(theta == .(a))) I want to have multiple items in the legend. All with greek letters. As a simple example, if I repeat the item twice the code does not work anymore a=123 plot(1,1) legend('bottomleft',legend=c(bquote(theta == .(a)),bquote(theta == .(a)))) I have tried many more complicated expressions but they all did not work. Any help will be appreciated. 回答1: In this case, plotmath is not able to coerce

Matplotlib: Color-coded text in legend instead of a line

纵饮孤独 提交于 2019-11-30 00:22:03
On certain LCD monitors, the color of the horizontal lines in the legend is hard to tell apart. (See the image attached). So instead of drawing a line in the legend, is it possible to just color code the text itself? so another words, have "y=0x" in blue, "y=1x" in green, etc... import matplotlib.pyplot as plt import numpy as np x = np.arange(10) fig = plt.figure() ax = plt.subplot(111) for i in xrange(5): ax.plot(x, i * x, label='$y = %ix$' % i) ax.legend() plt.show() PS. if the line could be made thicker just in the legend, but not in the plot, this would also work. Just set the linewidth of

How do I add two legends to a single plot in MATLAB?

雨燕双飞 提交于 2019-11-29 20:35:02
问题 I'd like to add two legends to a plot in MATLAB. How can I do this? 回答1: You could create a second superimposed axis, with a legend of its own (in a different location of course). EDIT: Here is a quick example: %# create some plot with a legend hAx(1) = axes(); hLine(1) = plot(1:10, 'Parent',hAx(1)); set(hAx(1), 'Box','off') legend(hLine(1), 'line') %# copy the axis hAx(2) = copyobj(hAx(1),gcf); delete( get(hAx(2),'Children') ) %# delete its children hLine(2) = plot(sin(1:10), 'Color','r',

ggplot2 manually specifying color & linetype - duplicate legend

故事扮演 提交于 2019-11-29 20:05:37
问题 I'm creating a plot with multiple linetypes, colors, and filled regions.The code below produces two legends (one shows line types, the other shows line colors) - and I need them to be combined into one legend that shows both linetype and linecolor. [there is a third legend showing the 'fill' objects, but that's fine] I followed the methodology given here: Controlling line color and line type in ggplot legend to try to get a single legend - but ended up with this double-legend behavior - what

Making a Legend/Key in GraphViz

老子叫甜甜 提交于 2019-11-29 19:51:05
I’d like to include a legend or key in my GraphViz diagram. I’m having trouble figuring out what code to use, though. I also want to put it in a corner, but the only coord I know for sure is the bottom-left: pos="10,10!" . Does anyone know how I can get this to work? digraph { rankdir=LR node [shape=plaintext] subgraph cluster_01 { label = "Legend"; key [label=<<table border="0" cellpadding="2" cellspacing="0" cellborder="0"> <tr><td align="right" port="i1">item 1</td></tr> <tr><td align="right" port="i2">item 2</td></tr> <tr><td align="right" port="i3">item 3</td></tr> <tr><td align="right"

R adding legend and directlabels to ggplot2 contour plot

依然范特西╮ 提交于 2019-11-29 18:12:45
问题 I have a raster map that I want to plot using ggplot2 using a continuous scale and labeled isolines on top of that. For that I'm using the directlabels package and am close to getting what I want but I can't get both the legend and the labeled isolines on the same map The following code reproduces my problem: install.packages(c('ggplot2', 'directlabels')) library('ggplot2') library('directlabels') df <- expand.grid(x=1:100, y=1:100) df$z <- df$x * df$y # Plot 1: this plot is fine but without

pandas pie chart plot remove the label text on the wedge

爱⌒轻易说出口 提交于 2019-11-29 17:15:55
问题 the pie chart example on pandas plotting tutorial http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html generates the following figure: with this code: import matplotlib.pyplot as plt plt.style.use('ggplot') import numpy as np np.random.seed(123456) import pandas as pd df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y']) f, axes = plt.subplots(1,2, figsize=(10,5)) for ax, col in zip(axes, df.columns): df[col].plot(kind='pie', autopct='%

One combined legend entry for multiple plots

拟墨画扇 提交于 2019-11-29 16:27:40
For some reason, I would like to plot the line and marker of the same data separately. data1 = (1:1:10)'; data2 = (1:2:10); figure(1); plot(data1,data1,'or'); hold on; plot(data2,data2,'-r'); legend('data'); However it will only display the legend for the first plot. And Matlab seems not to have option to manipulate the legend marker, color and linestyle. How can I make legend like this? Thanks! You will need to plot an invisible third plot (with almost no data to keep it fast) to define your legend: data1 = (1:1:10)'; data2 = (1:2:10); figure(1); plot(data1,data1,'or'); hold on plot(data2