legend

Wrap horizontal legend across multiple rows

北城余情 提交于 2020-01-01 02:10:14
问题 Suppose I have data like the following: lab <- "A really really long string!" dat <- data.frame(grp = paste(1:6,lab),x=1:6,y=runif(6)) When plotting a legend with strings this long, sometimes it can be a challenge to get the legend to fit nicely. If I have to I can always abbreviate the strings to shorten them, but I was wondering if it's possible (most likely using some grid magic) to 'wrap' a legend across multiple rows or columns. For instance, say I position the legend on the bottom,

Pandas bar plot with specific colors and legend location?

99封情书 提交于 2019-12-31 08:56:11
问题 I have a pandas DataFrame and I want to plot a bar chart that includes a legend. import pylab as pl from pandas import * x = DataFrame({"Alpha": Series({1: 1, 2: 3, 3:2.5}), "Beta": Series({1: 2, 2: 2, 3:3.5})}) If I call plot directly, then it puts the legend above the plot: x.plot(kind="bar") If I turn of the legend in the plot and try to add it later, then it doesn't retain the colors associated with the two columns in the DataFrame (see below): x.plot(kind="bar", legend=False) l = pl

Inserting a previously calculated value in a legend in matplotlib

半腔热情 提交于 2019-12-31 05:01:06
问题 This should be simple, but I haven't found it: I have a value (the coefficient R squared) previously calculated and I want to insert it in a legend in matplotlib. If the value calculated is r_squared , this is not working: plt.plot(x, y, linestyle='solid', color='k', label=r'Fitting line with $R^{2} = $, r_squared') It just don't read the value. Thanks. 回答1: You could just use string formatting : plt.plot(x, y, linestyle='solid', color='k', label="Fitting line with $R^{{2}} = {}".format(r

Inserting a previously calculated value in a legend in matplotlib

末鹿安然 提交于 2019-12-31 05:01:05
问题 This should be simple, but I haven't found it: I have a value (the coefficient R squared) previously calculated and I want to insert it in a legend in matplotlib. If the value calculated is r_squared , this is not working: plt.plot(x, y, linestyle='solid', color='k', label=r'Fitting line with $R^{2} = $, r_squared') It just don't read the value. Thanks. 回答1: You could just use string formatting : plt.plot(x, y, linestyle='solid', color='k', label="Fitting line with $R^{{2}} = {}".format(r

Duplicate legend with geom_vline() in ggplot

戏子无情 提交于 2019-12-31 03:20:13
问题 I want to create this graphic: aux_graf = structure(list(lines = structure(c(2L, 2L, 1L, 3L), .Label = c("h0", "ic", "median"), class = "factor"), values = c(21.19755, 23.06978, 24, 22.13366)), .Names = c("lines", "values"), row.names = c(NA, -4L), class = "data.frame") dadosGraf = structure(list(dados = c(18.7997, 20.5035, 18.6214, 19.9192, 21.117, 20.8353, 17.527, 17.078, 17.6197, 21.4255, 18.7545, 19.2026, 18.4187, 20.7641, 21.0553, 17.5905, 18.7561, 18.9772, 20.3084, 18.8988, 19.1688, 19

Remove legend key in matplotlib

梦想的初衷 提交于 2019-12-30 11:26:35
问题 I want to show a legend text but without a key (the rectangular box or line that appears by default). plt.hist(x, label = 'something') I don't want the box next to the legend "something". How to remove it? 回答1: First of all, you may decide not to create a legend at all and instead put some label in to corner of the plot. import matplotlib.pyplot as plt import numpy as np x = np.random.normal(size=160) plt.hist(x) plt.text(0.95,0.95, 'something', ha="right", va="top", transform=plt.gca()

Adding multiple legends to ggplot

与世无争的帅哥 提交于 2019-12-30 11:21:59
问题 I have following multi-layered plot: df <- data.frame(number = 1:10, values = rnorm(10), decision = factor(rbinom(10,1,.5), levels = c(0,1), labels=c("No","Yes")), expValues = rnorm(10), bandwidth = runif(10, 0,1)) ggplot(df,aes(x = number, y = values, color=decision)) + aes(group=NA) + geom_line(size = 1) + geom_point(size = 3,shape = 16) + geom_smooth(data = df, aes(ymin = values-bandwidth , ymax = values+bandwidth), stat = "identity") + geom_point(data=df, aes(x=number,y=expValues),shape =

Adding multiple legends to ggplot

ⅰ亾dé卋堺 提交于 2019-12-30 11:21:22
问题 I have following multi-layered plot: df <- data.frame(number = 1:10, values = rnorm(10), decision = factor(rbinom(10,1,.5), levels = c(0,1), labels=c("No","Yes")), expValues = rnorm(10), bandwidth = runif(10, 0,1)) ggplot(df,aes(x = number, y = values, color=decision)) + aes(group=NA) + geom_line(size = 1) + geom_point(size = 3,shape = 16) + geom_smooth(data = df, aes(ymin = values-bandwidth , ymax = values+bandwidth), stat = "identity") + geom_point(data=df, aes(x=number,y=expValues),shape =

Manually adding legend values in leaflet

眉间皱痕 提交于 2019-12-30 10:19:12
问题 I'm plotting results from various British elections in Leaflet and ran into a bit of a problem with legends. For the various results in the general election I'm using the same colour function with different domain for the different data (the yellow-> purple scale in the picture) This is created with (for the first two as examples): labvotescols <- colorNumeric( c("Yellow", "Purple"), domain = Westminster$LabourVotes, ukipvotescols <- colorNumeric( c("Yellow", "Purple"), domain = Westminster

Add legend to pie chart in dc.js

房东的猫 提交于 2019-12-30 09:35:17
问题 I'm building a dc.js-based visualization where one of the charts is a pie chart. See: http://jsfiddle.net/luiseth/t8we6/ The peculiarity of my case is that the labels that this chart will display are usually rather long, so much that usually get clipped by the chart's container (the <div> ). So I thought of having them appear on a legend, but I haven't been able to figure how to have the legend appear to the right of the chart. How can I do that? Playing around with the width has not helped