legend

pyplot legend label being truncated

左心房为你撑大大i 提交于 2019-12-11 00:13:21
问题 I'm trying to create a legend that will contain the color of the line it corresponds to and the label. My current code is plotting the legend but is only plotting the first letter of the label (D instead of DL11). I'm wondering how I can get my plot to stop truncating the label. I'd like to be able to add more lines and corresponding colors/labels in the future. Any help would be greatly appreciated. thanks from numpy import * import matplotlib.pyplot as plt import pylab data = loadtxt("/home

Combining Line and Barplot Legend in R

自古美人都是妖i 提交于 2019-12-10 22:32:05
问题 Is ther a way to do it? My current code: barplot(to_plot_bar,col=cm.colors(6,alpha=1),width=0.75,space=0.2,names.arg=x) lines(dat_dens,lty=1,col="black"); legend("topright",ltext,bty="n",fill=cm.colors(6), lty = c(0,0,0,0,0,0,1), lwd = c(0,0,0,0,0,1)); Generate such legend. 回答1: Try this ltext1 <- c(ltext,"emp") # this is not necessary if you already added legend("topright",ltext1,bty="n",col=c(cm.colors(6),"black"),pch=c(rep(15,6),-1), lty = c(0,0,0,0,0,0,1)); 来源: https://stackoverflow.com

Add a legend of colors in image {graphics}

一曲冷凌霜 提交于 2019-12-10 18:41:26
问题 In this example, I have an image with colors and I wonder if we can add a legend of colors. for example : points with z in [8:10] have color red and so on. x=runif(500,0,5) y=runif(500,0,5) z=floor(runif(500, 1,10)) xyz=data.frame(x,y,z) library(MBA) mba.int <- mba.surf(xyz, 300, 300, extend=T)$xyz.est image(mba.int, xaxs="i", yaxs="i") Thank you. 回答1: Thanks to @user20650, the answer is : fields::image.plot(mba.int, col = heat.colors(12)) 回答2: Something along the lines. Expand the logic and

why is the legend not present in the generated image if I use 'tight' for bbox_inches with the fig.legend method?

こ雲淡風輕ζ 提交于 2019-12-10 18:23:29
问题 I am trying to produce an image where I put the legend outside of the axes. But I find that if I use bbox_inches='tight' in the plt.savefig() method, the generated image does not contain the legend. A minimal working example to illustrate is as follows: import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl x = np.arange(-5, 5, 0.1) y1 = np.sin(x) y2 = np.cos(x) fig, ax1= plt.subplots(ncols=1, nrows=1, figsize=(10, 6)) ax1.plot(x, y1, label='sin(x)') ax1.plot(x, y2, label

How to change display format of legend in MATLAB

瘦欲@ 提交于 2019-12-10 17:54:33
问题 I am looking for a way to force the legend entries in a particular format. I following code, they are displayed like Instead I want it like 1e-1,1e-2,1e-3,1e-4, 1e-5. Is there a way to do this. MWE: sig=[0.1 0.01 0.001 0.0001 0.00001]; for j=1:length(sig) for x=1:10 Cost(j,x) = 2*x+j; end plot(1:10,Cost(j,:)); end legend(strcat('\sigma^2_n=',num2str((sig)'))); set(h,'Interpreter','latex') 回答1: You should specify that you'd like to use scientific notation when you convert sig to a string by

Setting a title for a legend in Matlab

核能气质少年 提交于 2019-12-10 16:32:32
问题 The following code is the most Minimal, Complete, and Verifiable example that I could find. My true case is much more complicated: x = 1:0.1:10; y = sin(x); subplot 211 plot(x,y) [leg,att] = legend('show'); title(leg,'my title') leg.Title.Visible = 'on'; subplot 212 plot(x,y) leg = legend('show'); title(leg,'my title') This results in: As you can clearly see, something is wrong with the upper legend title. Somehow, asking for the att output of the legend interfere with its' title. First, for

Matplotlib Legend Height in pixels

空扰寡人 提交于 2019-12-10 16:05:27
问题 I need to know the size of the legend in pixels. I seem to only be able to get height = 1. from any function... I've tried the following this returns 1. height = legend.get_frame().get_bbox_to_anchor().height this returns [0,0],[1.,1.] box = legend.get_window_extent().get_points() this also returns [0,0],[1.,1.] box = legend.get_frame().get_bbox().get_points() all of these return 1, even if the size of the legend changes! what's going on? 回答1: This is because you haven't yet drawn the canvas.

Matlab; Pie chart with 2+ / split legends R2017b

别来无恙 提交于 2019-12-10 16:03:32
问题 I'm creating a pie chart and ideally want the legend to be displayed horizontally at the top and/or bottom. However, in almost all cases this isn't possible as the legend go off the figure. Therefore, I'd ideally like to split the legend into two (or more) sub-legends and place them individually. I'm aware that this isn't a built-in feature in MATLAB (I'm using R2017b) but I'm not sure if it's something that can be bodged to work? I've seen a few people manage to do similar things with line

Is it possible to make a legend for Bubble Chart?

こ雲淡風輕ζ 提交于 2019-12-10 15:13:38
问题 Currently there is no example on the internet for a bubble chart having a legend, using dc.js, with the dc.legend() function. that.sessions_scatterplot .width(830) .height(350) .transitionDuration(1000) .margins({top: 100, right: 10, bottom: 30, left: 25}) .dimension(that.dim_Source) .group(that.fact_Source_Sessions) .ordinalColors(["#70c5a4","#8cd4f2","#fdc976","#9d97c8"]) .colorAccessor(function(d){ return d.value.src_category; }) .keyAccessor(function (d) { var x = d.value.avg_time/d.value

Achartengine legend location

强颜欢笑 提交于 2019-12-10 15:04:36
问题 Does anyone know how to change the location of the legend? I am trying to expand the graph to make use of all the space. So far I have mRenderer.setMargins(new int[] { 20, 30, -50, 0 }); This expands the graph lower but the legend stays in the same location so it is now above the x axis I tried mRenderer.setLegendHeight(5); with both negative and positive values. I'm not sure what this is supposed to do but it makes my graph go wayyyy low on the the screen (turns it into a scrollable view).