legend

Control the number of rows within a legend

寵の児 提交于 2019-12-04 00:30:59
I am currently trying to plot a large amount of data on a single plot. I have structured my representation using repeated colors and symbols. However, when plotting the final results, the legend appears slightly off because I cannot control the number of rows within it. Thus, instead of getting 5 repeated green, then 5 repeated red, 5 repeated blue then 2 other, I get 5 -4 -4 -4 (where I would have prefered 5 - 5 - 5 - 2) You can clearly see this in attached image. Right now I use these options for the legend: axp.legend(loc="lower right",ncol=4) I also had this problem a couple of times and

ggplot2 histogram legend too large

♀尐吖头ヾ 提交于 2019-12-03 21:25:06
I'm pretty happy with the results I'm getting with R. Most of my stacked histogram plots are looking fine, e.g. and However, I have a few that have so many categories in the legend that the legend is crowing out the plot, e.g. How can I fix this? Here is my plot.r, which I call on the command line like this RScript plot.r foo.dat foo.png 1600 800 foo.dat account,operation,call_count,day cal3510,foo-method,1,2016-10-01 cra4617,foo-method,1,2016-10-03 cus4404,foo-method,1,2016-10-03 hin4510,foo-method,1,2016-10-03 mas4484,foo-method,1,2016-10-04 ... entirety of foo.dat: http://pastebin.com

Centring legend below two plots in r

你说的曾经没有我的故事 提交于 2019-12-03 21:16:45
I would like to centre a common legend below two plots. I have used xpd=TRUE to allow for printing outside the plot itself and oma to create space for the legend. However the legend will not move horizonatally and gets clipped 'early' vertically. Any advice? quartz(title="PCoA",12,6) par(mfrow=c(1,2),oma=c(5,0,0,0),xpd=TRUE) plot(1:3,4:6,main="plot 1") plot(1:3,4:6,main="plot 2") # Clips the plot legend(1,3.5,ncol=3,c("0-1 km","1-5 km","outside barrier"),fill=c("green","orange","red"), title="Fetch") # Won't let me move the legend sideways legend(0,3.5,ncol=3,c("0-1 km","1-5 km","outside

Pandas stacked bar chart duplicates colors for large legends

流过昼夜 提交于 2019-12-03 20:20:55
I need to create a stacked bar chart with a large number (10 or so) categories. The problem is that Pandas only provides colors for up to 7 different categories. It sets the remaining colors as blue. How to I ensure that every category has a unique color? Example: df = pd.DataFrame(np.abs(np.random.randn(10,10)),columns=['A','B','C','D','E','F','G','H','I','J'], index=range(10)) df.plot(kind='bar',stacked=True,figsize=(20,10)) Produces a bar chart where H,I, and J are not given unique colors. In [22]: colors = plt.cm.GnBu(np.linspace(0, 1, 10)) In [23]: df.plot(kind='bar', stacked=True,

Plotting multiple functions and adding legends for them in ggplot2

会有一股神秘感。 提交于 2019-12-03 20:13:07
I want to plot y=log(1+x) and y=x in the range [-0.25, 0.25]. Here is my code so far - library(ggplot2) log1plusx <- function(x) log(1+x) self <- function(x) x ggplot(data.frame(x=c(-0.25, 0.25)), aes(x=x)) + stat_function(fun=log1plusx, color="red") + stat_function(fun=self, color="blue") I can't figure out how to add the legends for these two lines. Tried using guide_legend, but nothing works so far. Any ideas? Partial answer: ggplot(data.frame(x=c(-0.25, 0.25)), aes(x=x)) + geom_path(aes(colour="red"), stat="function", fun=log1plusx)+ geom_path(aes(colour="blue"), stat="function", fun=self)

Making a Legend/Key in GraphViz

故事扮演 提交于 2019-12-03 18:22:35
问题 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? 回答1: 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

Setting line colors in legend of MATLAB plot?

血红的双手。 提交于 2019-12-03 16:35:32
I am using the plotgauss2d function of BNT to visualize how the response of a 2D Gaussian node changes when evidence is observed elsewhere in the net. eng = jtree_inf_engine(bnet); evidence = cell(1, 2) eng = enter_evidence(eng, evidence); marginals = marginal_nodes(eng, 1); p_1 = marginals.T marginals = marginal_nodes(eng, 2); p_2 = marginals.T marginals clf; plotgauss2d(marginals.mu, marginals.Sigma); hold all; evidence{1} = 1; marginals = marginal_nodes(enter_evidence(eng, evidence), 2); p = plotgauss2d(marginals.mu, marginals.Sigma); set(p, 'Color', 'green'); evidence{1} = 2; marginals =

Adding key legend to multi-histogram plot in R

非 Y 不嫁゛ 提交于 2019-12-03 12:38:18
问题 How do I add a key legend to the below plot I whish to have a key legend somewhere in the upper right corner with two short horizontal color bars, where the red one should say "Plastic surgery gone wrong" and the blue one should say "Germany". I used the following code to produce the plot: bar2 <- read.table("div/ana-mut[...]/barriers-set-2.dat", sep=" ") bar2val <- c(bar2$V1, bar2$V2) bar3 <- read.table("div/ana-mut[...]/barriers-set-3.dat", sep=" ") bar3val <- c(bar3$V1, bar3$V2) p1 <- hist

Add table (aligned text blocks) to plot in R

烂漫一生 提交于 2019-12-03 12:04:29
I'd like to add a small table (for example as a legend) to a plot in R . I think of something like: t <- wantedTableMethod( row("param1", "param2", "param3", "param4") , row(value11, value12, value13, cell(value14, adj=0)) , row(value21, value22, value23, value24) , row(value31, value32, value33, cell(value34, adj=1)) border = F ) plot(1,1) legend("topleft", t) All values of a column should have the same offset. Is something like this possible in R , or do I need to align each value manually? The plotrix package has a addtable2plot function you can pass a data.frame or matrix to Using the

Text alignment in a Matplotlib legend

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 11:24:55
问题 I am trying to right-align the entries in a matplotlib axes legend (by default they are left-aligned), but can't seem to find any way of doing this. The setup I have is below: (I have added data and labels to my_fig axes using the ax.plot() command) ax = my_fig.get_axes()[0] legend_font = FontProperties(size=10) ax.legend(prop=legend_font, num_points=1, markerscale=0.5) There is a list of legend keyword arguments in the docs for matplotlib Axes, but there doesn't seem to be any straighforward