Normalizing Marker Size in Legend

Hi all,

I have a plot in which I have 15 markers, each with a separate size (created by calls to plot()). Because of this, the legend also shows variable size by default but I’d like all markers in the legend to have the same size.

I’m looking for an alternative to manually calling plot again with a standardized marker size (say 10.0) but plotting offscreen or with NANs. Thoughts I had were to either change the marker sizes after the legend is drawn (but it seems very difficult to update a legend post-creation) or to copy the handles and change the size that way (but I’ve yet to figure out how to make a hard copy of the plot handles). Any solutions?

···


Matthew Niznik

Matthew,

I think you’re on the right track. You need proxy artists of some sort. You can create Line2D objects directly, never add them to the figure, and then use those to create the legend.

An alternatively/hacky approach I often use is to the plot all the real data with ‘_nolegend’ labels, get my current (or desired) axes limits, then plot the negative value of my data with the symbology I want in the legend and restore my original axes limits. This works for me b/c I’m always dealing with rainfall or water quality data, so negative values aren’t really a thing for me to worry about. The concept is solid though:

  1. plot the data (no labels)

  2. record axes limit

  3. plot fake data far away from real data with legend-appropriate symbology

  4. restore axes limits

  5. create legend.

···

On Wed, Dec 4, 2013 at 3:48 PM, Matthew Niznik <matthew.niznik9@…287…> wrote:

Hi all,

I have a plot in which I have 15 markers, each with a separate size (created by calls to plot()). Because of this, the legend also shows variable size by default but I’d like all markers in the legend to have the same size.

I’m looking for an alternative to manually calling plot again with a standardized marker size (say 10.0) but plotting offscreen or with NANs. Thoughts I had were to either change the marker sizes after the legend is drawn (but it seems very difficult to update a legend post-creation) or to copy the handles and change the size that way (but I’ve yet to figure out how to make a hard copy of the plot handles). Any solutions?


Matthew Niznik


Sponsored by Intel(R) XDK

Develop, test and display web and hybrid apps with a single code base.

Download it for free now!

http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Matthew,

See the discussion at
http://matplotlib.1069221.n5.nabble.com/Legend-Marker-Color-Bug-td38695.html

-Sterling

···

On Dec 4, 2013, at 3:48PM, Matthew Niznik wrote:

Hi all,

I have a plot in which I have 15 markers, each with a separate size (created by calls to plot()). Because of this, the legend also shows variable size by default but I'd like all markers in the legend to have the same size.

I'm looking for an alternative to manually calling plot again with a standardized marker size (say 10.0) but plotting offscreen or with NANs. Thoughts I had were to either change the marker sizes after the legend is drawn (but it seems very difficult to update a legend post-creation) or to copy the handles and change the size that way (but I've yet to figure out how to make a hard copy of the plot handles). Any solutions?

--
Matthew Niznik
------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options