legend

Global legend using grid.arrange (gridExtra) and lattice based plots

喜欢而已 提交于 2019-11-29 08:25:21
I am producing four plots using xyplot (lattice) and further combine them with grid.arrange (gridExtra). I would like to obtain a graph with a common global legend. The closest that I have reached is the following. They have to be in a matrix layout, otherwise an option would be to put them in a column and include only a legend for the top or bottom one. # Load packages require(lattice) require(gridExtra) # Generate some values x1<-rnorm(100,10,4) x2<-rnorm(100,10,4) x3<-rnorm(100,10,4) x4<-rnorm(100,10,4) y<-rnorm(100,10,1) cond<-rbinom(100,1,0.5) groups<-sample(c(0:10),100,replace=TRUE)

Fill the right column of a matplotlib legend first

大憨熊 提交于 2019-11-29 08:02:34
Hey I am trying to fit a legend onto a plot so that it doesn't obscure the graph. import numpy as np import matplotlib.pyplot as plt X = np.linspace(0,100,11) plt.plot(X,-X, label='plot 1') plt.plot(X,-2*X, label='plot 2') plt.plot(X,-3*X, label='plot 3') leg=plt.legend(ncol=2) leg.get_frame().set_visible(False) plt.show() So in the minimum working example, above, what I want to be able to do is move the 'plot 2' label in the legend into the right column, i.e. directly under 'plot 3'. Any help would be appreciated, thanks. The legend is filling in the columns from left to right. In other words

Matplotlib adding legend based on existing color series

你。 提交于 2019-11-29 07:44:31
I plotted some data using scatter plot and specified it as such: plt.scatter(rna.data['x'], rna.data['y'], s=size, c=rna.data['colors'], edgecolors='none') and the rna.data object is a pandas dataframe that is organized such that each row represents a data point ('x' and 'y' represents the coordinate and 'colors' is an integer between 0-5 representing the color of the point). I grouped the data points into six distinct clusters numbered 0-5, and put the cluster number at each cluster's mean coordinates. This outputs the following graph: I was wondering how I can add a legend to this plot

How to add legend to imshow() in matplotlib

荒凉一梦 提交于 2019-11-29 07:12:29
I am using matplotlib In plot() or bar() , we can easily put legend, if we add labels to them. but what if it is a contourf() or imshow() I know there is a colorbar() which can present the color range, but it is not satisfied. I want such a legend which have names(labels). For what I can think of is that, add labels to each element in the matrix, then ,try legend(), to see if it works, but how to add label to the element, like a value?? in my case, the raw data is like: 1,2,3,3,4 2,3,4,4,5 1,1,1,2,2 for example, 1 represents 'grass', 2 represents 'sand', 3 represents 'hill'... and so on.

independently move 2 legends ggplot2 on a map

前提是你 提交于 2019-11-29 05:05:52
I want to independently move two legends on a map to save save and make the presentation nicer. Here is the data: ## INST..SUB.TYPE.DESCRIPTION Enrollment lat lng ## 1 CHARTER SCHOOL 274 42.66439 -73.76993 ## 2 PUBLIC SCHOOL CENTRAL 525 42.62502 -74.13756 ## 3 PUBLIC SCHOOL CENTRAL HIGH SCHOOL NA 40.67473 -73.69987 ## 4 PUBLIC SCHOOL CITY 328 42.68278 -73.80083 ## 5 PUBLIC SCHOOL CITY CENTRAL 288 42.15746 -78.74158 ## 6 PUBLIC SCHOOL COMMON NA 43.73225 -74.73682 ## 7 PUBLIC SCHOOL INDEPENDENT CENTRAL 284 42.60522 -73.87008 ## 8 PUBLIC SCHOOL INDEPENDENT UNION FREE 337 42.74593 -73.69018 ## 9

Adding a chart legend in D3

我只是一个虾纸丫 提交于 2019-11-29 04:34:18
问题 I am having trouble adding a chart legend to my d3js chart. Here is my current approach: var legend = svg.append("g") .attr("class", "legend") .attr("x", w - 65) .attr("y", 25) .attr("height", 100) .attr("width", 100); legend.append("rect") .attr("x", w - 65) .attr("y", 25) .attr("width", 10) .attr("height", 10) .style("fill", function(d) { return color_hash[dataset.indexOf(d)][1] }); legend.append("text") .attr("x", w - 65) .attr("y", 25) .text(function(d) { return color_hash[dataset.indexOf

Change Silverlight Chart Legend Item Layout

强颜欢笑 提交于 2019-11-29 03:53:37
I am working on customizing the layout of a Silverlight Toolkit Chart. I have two requirements: 1) Move the Legend area to the bottom of the chart (solved). 2) change the layout of elements within the legend to be displayed next to each other, ie. {legend 1},{legend 2},{legend 3}, rather than the default column format. 1) was easy to solve with a ControlTemplate (see below). 2) How do I change the layout of legend items? Can it be done by further customizing the Chart's ControlTemplate, or does the Legend need its own ControlTemplate? The Chart itself is defined as: <chartingToolkit:Chart Name

Add annotation and segments to groups of legend elements

℡╲_俬逩灬. 提交于 2019-11-29 03:28:11
问题 My ggplot has the following legend: I want to group my individual legend variables, and add the group names and "brackets" like shown in legend below: My data has 2 columns: 1 - States of USA 2 - Activity level which has a range from 10 (High) - 1 (Low) I am also using data - us<-map_data("state"), which is included in ggplot/map package. My code: ggplot()+ geom_map(data=us, map=us,aes(x=long, y=lat, map_id=region), fill="#ffffff", color="#ffffff", size=0.15) + geom_map(data=dfm4,map=us,aes

MATLAB graph plotting: assigning legend labels during plot

∥☆過路亽.° 提交于 2019-11-29 03:00:22
问题 I am plotting data in a typical MATLAB scatterplot format. Ordinarily when plotting multiple datasets, I would use the command 'hold on;', and then plot each of the data, followed by this to get my legend: legend('DataSet1', 'DataSet2') % etcetera However, the (multiple) datasets I am plotting on the same axes are not necessarily the same datasets each time. I am plotting up to six different sets of data on the same axes, and there could be any combination of these shown (depending on what

pyplot combine multiple line labels in legend

耗尽温柔 提交于 2019-11-29 02:50:07
问题 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