legend

ggplot2 histogram legend too large

僤鯓⒐⒋嵵緔 提交于 2019-12-05 06:24:30
问题 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

Pandas stacked bar chart duplicates colors for large legends

老子叫甜甜 提交于 2019-12-05 05:51:43
问题 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.

Angular ngx-charts options for customizing the Legend?

邮差的信 提交于 2019-12-05 04:16:50
I am currently using ngx-charts for Angular2, and I would like to customize some legends, e.g. place the legend below the chart, or rename the legend fields, or make the legend wider (parts of the text just gets cut off..) etc. Are there any good options to customize the legend? Or is it generally not possible, or what is the best way to do it? Currently, my chart legends look like this: Some legends are too wide, some are cut off, and I'd like to position the legend e.g below the chart... Legend Position To position the legend below the chart, you can use the legendPosition input: <ngx-charts

Writing variables as subscripts in math mode

主宰稳场 提交于 2019-12-05 03:44:02
问题 I am trying to plot some data, using a for loop to plot distributions. Now I want to label those distributions according to the loop counter as the subscript in math notation. This is where I am with this at the moment. import matplotlib.pyplot as plt import numpy as np import matplotlib.mlab as mlab mean = [10,12,16,22,25] variance = [3,6,8,10,12] x = np.linspace(0,40,1000) for i in range(4): sigma = np.sqrt(variance[i]) y = mlab.normpdf(x,mean[i],sigma) plt.plot(x,y,label=$v_i$) # where i

Highcharts - fire legendItemClick event

偶尔善良 提交于 2019-12-05 03:19:24
I want to fire the same event that it's fired when you select an item legend but from an external html button. Is it possible? I've created a jsfiddle to show it: http://jsfiddle.net/YcJF8/1/ . $('#container').highcharts({ chart : { type : 'spline', }, xAxis : { categories : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] }, series : [{ data : [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4], }], plotOptions : { series : { cursor : 'pointer', } }, }); $('#button').click(function() { alert("Fire legenditemclick event"); }); In

Plotting multiple functions and adding legends for them in ggplot2

允我心安 提交于 2019-12-05 02:57:31
问题 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? 回答1: Partial answer: ggplot(data.frame(x=c(-0.25, 0.25)), aes(x=x)) + geom_path

ggplot2: One legend with two visual properties derived from common variable

孤人 提交于 2019-12-05 02:36:16
How can I get a single legend that captures both colour and size? I was under the impression that a common legend is default if a common variable is used, but the following example shows I am missing something. library(ggplot2) input <- as.data.frame(matrix(runif(60),nrow=20,ncol=3)) colnames(input) <- c("A","B","C") p <- ggplot(input,aes(A,B,size=C,color=C)) + geom_point() Thanks to Arun for a comment that prompted this edit. So, if one just uses size (and forgets color) one gets a legend that depicts three sizes but many more sizes are depicted in the plot. So what I would be after is

how to align the legend title to the middle of legend box in ggplot2?

陌路散爱 提交于 2019-12-05 00:36:07
I want to move the legend title sex a little right to the horizontal center of legend box. I tried theme and guide_legend but failed. Both ways won't change the legend title position. # example data from http://www.cookbook-r.com/Graphs/Legends_(ggplot2)/ df1 <- data.frame( sex = factor(c("Female","Female","Male","Male")), time = factor(c("Lunch","Dinner","Lunch","Dinner"), levels=c("Lunch","Dinner")), total_bill = c(13.53, 16.81, 16.24, 17.42) ) library(ggplot2) p <- ggplot(data=df1, aes(x=time, y=total_bill, group=sex, shape=sex, colour=sex)) + geom_line() + geom_point() # no change p +

Legend box width not correct when using par

 ̄綄美尐妖づ 提交于 2019-12-04 20:51:00
问题 I have the problem , that my legend is too large, my code: par(mfrow=c(1,2)) hist(alvsloss,breaks = 100, freq=F,main="Histogramm, density curve (gaussian kernel) \n and fitted normal distribution of Allianz simple losses ",xlim=c(-0.15,0.15),xlab="loss",ylab="density",cex.axis=1.2,cex.lab=1.2) lines(density(alvsloss), col="black", lwd=2) curve(dnorm(x, mean = mean(alvsloss), sd = sd(alvsloss)), add=TRUE, col="black",lwd=2,lty="dotted") legend(-0.155, 30, c("(Gaussian) Kernel density","fitted

How to add legend below subplots in matplotlib?

…衆ロ難τιáo~ 提交于 2019-12-04 19:35:56
I am trying to add a legend below a 3-column subplot figure. I have tried the following: fig, ax = plt.subplots(ncols=3) ax[0].plot(data1) ax[1].plot(data2) ax[2].plot(data3) ax_sub = plt.subplot(111) box = ax_sub.get_position() ax_sub.set_position([box.x0, box.y0 + box.height * 0.1,box.width, box.height * 0.9]) ax_sub.legend(['A', 'B', 'C'],loc='upper center', bbox_to_anchor=(0.5, -0.3),fancybox=False, shadow=False, ncol=3) plt.show() However, this creates just one empty frame. When I comment out the ax_sub part, my subplots show up nice (but without a legend...)... Many thanks! This is