legend

advanced customization of legend markers in matlab

荒凉一梦 提交于 2019-11-30 15:54:20
问题 It is relatively simple to add basic modifications to markers in matlab legends. The legend produced by the following code snippet (): hold on h = plot(inf,inf,'ob',inf,inf,'r+'); legend(h,'Data1','Data2'); Can be easily modified to: using the following code: [~,~,icons,~] = legend(h,'Data1','Data2'); set(icons(1),'LineStyle','-') set(icons(2),'LineStyle','-') However things become fairly complicated if I want to correctly legend objects such as (circle is not in the middle of a line) or

ggplot2 manually specifying color & linetype - duplicate legend

限于喜欢 提交于 2019-11-30 14:13:44
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 have I done wrong? library(ggplot2) library(scales) data = structure(list(Dates = structure(c

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

别来无恙 提交于 2019-11-30 14:01:21
I'd like to add two legends to a plot in MATLAB. How can I do this? 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', 'Parent',hAx(2)); set(hAx(2), 'Color','none', 'XTick',[], ... 'YAxisLocation','right', 'Box','off') %# make it

R adding legend and directlabels to ggplot2 contour plot

浪尽此生 提交于 2019-11-30 12:39:59
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 contours p <- ggplot(aes(x=x, y=y, z=z), data = df) + geom_raster(data=df, aes(fill=z)) + scale_fill

pandas pie chart plot remove the label text on the wedge

假如想象 提交于 2019-11-30 11:36:49
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='%.2f', labels=df.index, ax=ax, title=col, fontsize=10) ax.legend(loc=3) plt.show() I want to remove the

Creating legend with circles leaflet R

泪湿孤枕 提交于 2019-11-30 09:14:43
I'm trying to create a leaflet map with points sized by a variable. Is it possible to create a legend with different sized circles representing the different variable values? I found another post showing how to convert squares to circles in the legend, but am not sure how to change the size of different circles in the legend. For example, here's a dummy script which creates 10 points associated with 2 classes of a variable (5 and 10). I'd like a legend with two circles the same size as that specified with addCircleMarkers with a radius of 5 and 10. If anyone can modify to create what I want I

matplotlib - Legend in separate subplot

↘锁芯ラ 提交于 2019-11-30 09:02:39
I am plotting an array of pie charts, each using the same two colors for the same two types of data. plt.figure(num=None, figsize=(6, 8)) for i in range(len(data_1)): plt.subplot(sp_rows, sp_cols, i+1) fracs = [data_1[i], data_2[i]] plt.pie(fracs, autopct='%1.1f%%') pp.savefig() Obviously it doesn't make sense to plot a legend for every one of these charts, since they are all the same. So is there any way I can plot a single legend into a separate subfigure at the end? You can call legend() only once: import numpy as np import pylab as pl for i in xrange(1, 5): pl.subplot(220+i) pl.pie([i,2],

How to add legend to imshow() in matplotlib

走远了吗. 提交于 2019-11-30 08:39:08
问题 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

How do I change the legend position in a NVD3 chart?

拜拜、爱过 提交于 2019-11-30 08:26:43
Does anyone know how to reposition the legend in a NVD3 chart relative to the graph itself? It is on top by default, and I would like it to go on the side (better use of space within my app) An example of what I would like to do: There is AFAIK no option to do this, but you can select the g element that contains the legend manually and move it, e.g. d3.select(".nv-legendWrap") .attr("transform", "translate(100,100)"); Michael As of this writing (2 jul 2015) nvd3 supports putting the legend to the right of the pie chart. When you initialize the graph, set legendPosition to right . Example: nv

Position the legend outside the plot area with Bokeh

半腔热情 提交于 2019-11-30 07:39:09
I am making a plot following the example found here Unfortunately, I have 17 curves I need to display, and the legend overlaps them. I know I can create a legend object that can be displayed outside the plot area like here , but I have 17 curves so using a loop is much more convenient. Do you know how to combine both methods? Ok, I found the solution. See the code below where I have just modified the interactive legend example: import pandas as pd from bokeh.palettes import Spectral4 from bokeh.plotting import figure, output_file, show from bokeh.sampledata.stocks import AAPL, IBM, MSFT, GOOG