Re: [Matplotlib-users] Scale legend box border, dashed and dotted lines when the figure size is changed

2010-07-13 Thread Eric Firing
On 07/12/2010 01:11 PM, John Hunter wrote:
> On Mon, Jul 12, 2010 at 5:11 PM, Jeffrey Blackburne  wrote:
>> Actually, I have been able to do it like this:
>>
>> mpl.rcParams['patch.linewidth'] = 0.2
>>
>> Hope that helps, and sorry I didn't reply sooner.
>
> Of course this will affect any other patches in your figure (eg
> Rectangles from histogram plots, etc).
>
> I am not opposed to adding some legend.frame rc parameters.  Part of
> the purpose of the rc file is to work like a style sheet, so if you
> are writing a book or an article with a bunch of figures, and you want
> them all the have the same look-and-feel, you can customize the
> defaults externally w/o a bunch of boilerplate in your scripts that
> can be difficult to maintain.  It seems like the legend frame
> properties fit into this category.  In particular, the frame alpha is
> one I almost always set to semi-transparent so you can see data behind
> the legend, which is boilerplate I might be happy to do away with if I
> had an rc param.
>
> I would be amenable to adding:
>
>legend.frame.facecolor : 'white'
>legend.frame.edgecolor : 'white'
>legend.frame.linewidth : 1.0
>legend.frame.alpha : 1.0
>
> but I'd like to hear from others (Eric?) who are already not happy
> with the size of our rc file.  Although this change would increase the
> line count, it doesn't increase the complexity much if at all in my
> view and is somewhat useful.  It would imply some mild potential
> breakage, because currently the legend face and edge colors use the
> axes colors (which is why it would be nice if we had
> containment/inheritance for our rc params so they could inherit from
> parent) so if someone has tweaked their old axes.facecolor, they would
> need to add legend.frame.facecolor under this change to remain
> compatible.

John,

I have no objections to the change you propose, and your idea of adding 
inheritance sounds good, also.  Even nicer might be some flexibility in 
specifying units, so that a pad could scale with fontsize instead of 
being given in points, for example.

My reservations about the rc file approach come partly from the concern 
that it can be too hidden, especially when the filename is prefixed with 
a dot--which, fortunately, we don't do.  Still, a user might 
understandably wonder where the active configuration file really is,
(hint to other readers: try the matplotlib function, matplotlib_fname()) 
and having a program behave differently depending on the current working 
directory when it is run is a double-edged sword.

Style-file functionality is clearly a good thing, so the question is 
whether to make it explicit.  One way to make it more explicit would be 
to invoke it via a script's command line, just as the backend can be 
specified via the command line.  I don't know if it is worth adding this 
as an option, but it might facilitate testing, if nothing else. 
Potentially, the style-file parts of a matplotlibrc file could also be 
read in by a function at any point in a script.

I was also unhappy with situations where the rc mechanism--which really 
should be used for global configuration--was the only mechanism 
available for local customization.  I don't know whether there are still 
such cases, but the one that particularly bothered me--tick 
customization--can now be done without setting and resetting rc parameters.

Enough idle rumination...

Eric

>
> JDH
>
> --
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Scale legend box border, dashed and dotted lines when the figure size is changed

2010-07-12 Thread John Hunter
On Mon, Jul 12, 2010 at 5:11 PM, Jeffrey Blackburne  wrote:
> Actually, I have been able to do it like this:
>
> mpl.rcParams['patch.linewidth'] = 0.2
>
> Hope that helps, and sorry I didn't reply sooner.

Of course this will affect any other patches in your figure (eg
Rectangles from histogram plots, etc).

I am not opposed to adding some legend.frame rc parameters.  Part of
the purpose of the rc file is to work like a style sheet, so if you
are writing a book or an article with a bunch of figures, and you want
them all the have the same look-and-feel, you can customize the
defaults externally w/o a bunch of boilerplate in your scripts that
can be difficult to maintain.  It seems like the legend frame
properties fit into this category.  In particular, the frame alpha is
one I almost always set to semi-transparent so you can see data behind
the legend, which is boilerplate I might be happy to do away with if I
had an rc param.

I would be amenable to adding:

  legend.frame.facecolor : 'white'
  legend.frame.edgecolor : 'white'
  legend.frame.linewidth : 1.0
  legend.frame.alpha : 1.0

but I'd like to hear from others (Eric?) who are already not happy
with the size of our rc file.  Although this change would increase the
line count, it doesn't increase the complexity much if at all in my
view and is somewhat useful.  It would imply some mild potential
breakage, because currently the legend face and edge colors use the
axes colors (which is why it would be nice if we had
containment/inheritance for our rc params so they could inherit from
parent) so if someone has tweaked their old axes.facecolor, they would
need to add legend.frame.facecolor under this change to remain
compatible.

JDH

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Scale legend box border, dashed and dotted lines when the figure size is changed

2010-07-12 Thread Jeffrey Blackburne

On Jul 12, 2010, at 5:45 PM, Janne Blomqvist wrote:

>>> a.legend()
>>
>> Change this to
>>
>>  lg = a.legend()
>>  fr = lg.get_frame()
>>  fr.set_lw(0.2)
>
> Thanks, this solved it. A bit annoying that it can't be done with rc
> params, but hey, at least it works.

Hi Janne,

Actually, I have been able to do it like this:

mpl.rcParams['patch.linewidth'] = 0.2

Hope that helps, and sorry I didn't reply sooner.

-Jeff


--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Scale legend box border, dashed and dotted lines when the figure size is changed

2010-07-12 Thread Janne Blomqvist
On Sat, Jul 10, 2010 at 18:42, Jouni K. Seppänen  wrote:
> Janne Blomqvist  writes:
>
>> The problem I'm having is that as the figure is then pretty small, I
>> can scale font sizes, axis sizes, line widths etc., but what I've been
>> unable to figure out is how to scale dashed or dotted lines, as well
>> as the thickness of the legend border box.
>
> It seems that there are no rc settings for these, but you can adjust
> them as follows:
>
>> a.plot(x, y, '--', label='foo bar')
>
> Change this to
>
>  a.plot(x, y, '--', label='foo bar', dashes=(2,2))
>
> The value of dashes is the number of points of ink followed by the
> number of points of whitespace. It defaults to (6,6) for the '--'
> linestyle (found in the dashd dictionary of backend_bases.py).
>
>> a.legend()
>
> Change this to
>
>  lg = a.legend()
>  fr = lg.get_frame()
>  fr.set_lw(0.2)

Thanks, this solved it. A bit annoying that it can't be done with rc
params, but hey, at least it works.


-- 
Janne Blomqvist

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Scale legend box border, dashed and dotted lines when the figure size is changed

2010-07-10 Thread Jouni K . Seppänen
Janne Blomqvist  writes:

> The problem I'm having is that as the figure is then pretty small, I
> can scale font sizes, axis sizes, line widths etc., but what I've been
> unable to figure out is how to scale dashed or dotted lines, as well
> as the thickness of the legend border box. 

It seems that there are no rc settings for these, but you can adjust
them as follows:

> a.plot(x, y, '--', label='foo bar')

Change this to 

  a.plot(x, y, '--', label='foo bar', dashes=(2,2))

The value of dashes is the number of points of ink followed by the
number of points of whitespace. It defaults to (6,6) for the '--'
linestyle (found in the dashd dictionary of backend_bases.py).

> a.legend()

Change this to

  lg = a.legend()
  fr = lg.get_frame()
  fr.set_lw(0.2)

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Scale legend box border, dashed and dotted lines when the figure size is changed

2010-07-09 Thread Janne Blomqvist
Hi,

I posted this to stackoverflow
(http://stackoverflow.com/questions/3190798/scale-legend-box-border-dashed-and-dotted-lines-when-the-figure-size-is-changed),
but didn't get any answer, so here goes again:

I'm trying to use matplotlib to prepare some figures for publication.
In order to make the font sizes match the text of the manuscript I'm
trying to create the figure in the final size to begin with, so that I
avoid scaling the figure when inserting it into the manuscript.

The problem I'm having is that as the figure is then pretty small, I
can scale font sizes, axis sizes, line widths etc., but what I've been
unable to figure out is how to scale dashed or dotted lines, as well
as the thickness of the legend border box. For a simplified and
somewhat exaggerated example, consider


#!/usr/bin/python

small = True


from matplotlib import use
use('pdf')

from matplotlib import rc
rc('ps', usedistiller='xpdf')
rc('text', usetex=True)

if small:
   figsize = (1.0, 0.5)
   rc('font', size=2)
   rc('axes', labelsize=2, linewidth=0.2)
   rc('legend', fontsize=2, handlelength=10)
   rc('xtick', labelsize=2)
   rc('ytick', labelsize=2)
   rc('lines', lw=0.2, mew=0.2)
   rc('grid', linewidth=0.2)
else:
   figsize = (8,8)

import numpy as np

x = np.arange(0, 10, 0.001)
y = np.sin(x)

import matplotlib.pyplot as plt
f = plt.figure(figsize=figsize)
a = f.add_subplot(111)
a.plot(x, y, '--', label='foo bar')
a.legend()
f.savefig('mplt.pdf')

If you change the first executable line to small = False you can see
how it should look in "normal" size. Compared to the normal size, the
small plot suffers from a legend box with too thick borders, and the
dashed line is too coarse, i.e. too long dashes and too long distance
between the dashes.

So my question is, is there a way to fix these two problems?

The matplotlib version I'm using is 0.99.1.2 on ubuntu 10.04 amd64.


-- 
Janne Blomqvist

--
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users