rc params strangeness/error

Matplotlib 0.98.5.2
Location: C:\leo.matplotlib
Running Windows XP SP2
Obtained from pythonxy v. 2.1.10
No rc customizations …

I’ve been having a devil of a time getting my rcParams to update mid-script. Perhaps this isn’t possible, but if that’s so, it’s not entirely clear. Even if it is so, this is seemingly a defect, because in an interactive session one expects quite different behavior (and no amount of iPython %reset-ing seems to be able to help).

Note that manually setting the font (or what have you) in title works fine.

Here is some example code:

############## BEGIN #########
import matplotlib
from matplotlib import rc, rcParams, rcdefaults
from matplotlib.pyplot import plot, show, figure, title

print matplotlib.version
print matplotlib.get_configdir()
print
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]
print
figure(4)
title(‘This should be in a sans-serif font’)
show()

rcParams[‘font.sans-serif’] = rcParams[‘font.monospace’]
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]
print
figure(1)
title(‘This should be in a monospace font’)
show()

rcParams[‘font.sans-serif’] = rcParams[‘font.serif’]
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]
print
figure(2)
title(‘This should be in a serif font’)
show()

rcdefaults()
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]
print
figure(3)
title(‘This should be back to a sans-serif font’)
show()
######### END ####################

Matplotlib 0.98.5.2
Location: C:\leo.matplotlib
Running Windows XP SP2
Obtained from pythonxy v. 2.1.10
No rc customizations …

I’ve been having a devil of a time getting my rcParams to update mid-script. Perhaps this isn’t possible, but if that’s so, it’s not entirely clear. Even if it is so, this is seemingly a defect, because in an interactive session one expects quite different behavior (and no amount of iPython %reset-ing seems to be able to help).

Note that manually setting the font (or what have you) in title works fine.

Here is some example code:

############## BEGIN #########
import matplotlib
from matplotlib import rc, rcParams, rcdefaults

from matplotlib.pyplot import plot, show, figure, title

print matplotlib.version
print matplotlib.get_configdir()
print
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]

print ‘family is:’, rcParams[‘font.family’]
print
figure(4)
title(‘This should be in a sans-serif font’)
show()

rcParams[‘font.sans-serif’] = rcParams[‘font.monospace’]

print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]
print
figure(1)
title(‘This should be in a monospace font’)

show()

rcParams[‘font.sans-serif’] = rcParams[‘font.serif’]
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]

print
figure(2)
title(‘This should be in a serif font’)
show()

rcdefaults()
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]

print
figure(3)
title(‘This should be back to a sans-serif font’)
show()
######### END ####################

Hi,

Did anyone have any insight on this? Alternatively, anyone know why there has been little uptake on this question …(apologies that it was accidentally sent twice)?

Leo

···

On Tue, Feb 3, 2009 at 11:42 PM, Leo Trottier <leo@…2479…> wrote:

Matplotlib 0.98.5.2
Location: C:\leo.matplotlib
Running Windows XP SP2
Obtained from pythonxy v. 2.1.10
No rc customizations …

I’ve been having a devil of a time getting my rcParams to update mid-script. Perhaps this isn’t possible, but if that’s so, it’s not entirely clear. Even if it is so, this is seemingly a defect, because in an interactive session one expects quite different behavior (and no amount of iPython %reset-ing seems to be able to help).

Note that manually setting the font (or what have you) in title works fine.

Here is some example code:

############## BEGIN #########
import matplotlib
from matplotlib import rc, rcParams, rcdefaults

from matplotlib.pyplot import plot, show, figure, title

print matplotlib.version
print matplotlib.get_configdir()
print
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]

print ‘family is:’, rcParams[‘font.family’]
print
figure(4)
title(‘This should be in a sans-serif font’)
show()

rcParams[‘font.sans-serif’] = rcParams[‘font.monospace’]

print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]
print
figure(1)
title(‘This should be in a monospace font’)

show()

rcParams[‘font.sans-serif’] = rcParams[‘font.serif’]
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]

print
figure(2)
title(‘This should be in a serif font’)
show()

rcdefaults()
print “rcParams[‘font.sans-serif’]:”, rcParams[‘font.sans-serif’]
print ‘family is:’, rcParams[‘font.family’]

print
figure(3)
title(‘This should be back to a sans-serif font’)
show()
######### END ####################

matplotlib is inconsistent in its treatment of rcParams. Some have immediate side effects, others are cached during initialization and changing them later has no effect. This is a long standing problem, but not one with an easy solution, since the caching, particularly in the case of font lookup, is an important optimization.

Personally, I feel that rcParams should be primarily for environmental settings, and thus should not be updatable after initialization -- but that's only my opinion -- I have heard the opposite argued rather convincingly. In my opinion, it is the inconsistency between rcParams (or lack of documentation about when they are effective) that is worth addressing.

In your particular case, there is an easy non-rcParam alternative -- just send text parameters to the title command.

Mike

Leo Trottier wrote:

···

Hi,

Did anyone have any insight on this? Alternatively, anyone know why there has been little uptake on this question ...(apologies that it was accidentally sent twice)?

Leo

On Tue, Feb 3, 2009 at 11:42 PM, Leo Trottier <leo@...2479... > <mailto:leo@…2479…>> wrote:

    Matplotlib 0.98.5.2
    Location: C:\leo\.matplotlib
    Running Windows XP SP2
    Obtained from pythonxy v. 2.1.10
    No rc customizations ...

    I've been having a devil of a time getting my rcParams to update
    mid-script. Perhaps this isn't possible, but if that's so, it's
    not entirely clear. Even if it is so, this is seemingly a defect,
    because in an interactive session one expects quite different
    behavior (and no amount of iPython %reset-ing seems to be able to
    help).

    Note that manually setting the font (or what have you) in *title*
    works fine.

    Here is some example code:

    ############## BEGIN #########
    import matplotlib
    from matplotlib import rc, rcParams, rcdefaults
    from matplotlib.pyplot import plot, show, figure, title

    print matplotlib.__version__
    print matplotlib.get_configdir()
    print
    print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
    print 'family is:', rcParams['font.family']
    print
    figure(4)
    title('This should be in a sans-serif font')
    show()

    rcParams['font.sans-serif'] = rcParams['font.monospace']
    print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
    print 'family is:', rcParams['font.family']
    print
    figure(1)
    title('This should be in a monospace font')
    show()

    rcParams['font.sans-serif'] = rcParams['font.serif']
    print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
    print 'family is:', rcParams['font.family']
    print
    figure(2)
    title('This should be in a serif font')
    show()

    rcdefaults()
    print "rcParams['font.sans-serif']:", rcParams['font.sans-serif']
    print 'family is:', rcParams['font.family']
    print
    figure(3)
    title('This should be back to a sans-serif font')
    show()
    ######### END ####################

------------------------------------------------------------------------

------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA