Re: [Matplotlib-users] using different font families with?LaTeX-generated text

2007-05-14 Thread Alexander Schmolck
Darren Dale <[EMAIL PROTECTED]> writes:

> On Monday 14 May 2007 9:02:08 am Lev Givon wrote:
>> In the matplotlib-users list archive, I noticed that someone once
>> mooted the possibility of patching the matplotlib LaTeX code to
>> provide a user-configurable parameter that would allow one to add
>> extra lines to the LaTeX preamble. I didn't see any responses from the
>> matplotlib developers regarding their opinions of the suggested patch,
>> however.
>
> I am not in favor of adding a parameter that allows users to add additional 
> lines to the preamble. It took a lot of work to get usetex working on all 
> platforms, and I just don't have the kind of time anymore to add an option 
> that will allow endless configuration of latex parameters. It's not the 
> implementation of the patch that is the problem, it is all the support 
> requests that will follow from latex-specific failures related to customized 
> preamble settings.

I'd *really* like the ability to ``usepackage`` for various reasons and it
would clearly add useful functionality that is not otherwise obtainable.

I understand concern about an additional support burden, but couldn't this be
handled by explicitly noting that it's unsupported, possibly even printing out
an unsubtle warning like so:

warnings.warn("""
***
* YOU SPECIFIED A CUSTOM LATEX-PREAMBLE -- THIS IS AN UNSUPPORTED FEATURE.  
  *
* PLEASE DO NOT REPORT PROBLEMS TO matplotlib-users@lists.sourceforge.net   
  *
* BEFORE YOU HAVE REMOVED YOUR latex_preamble=... SETTING.  
  *
***
""")

?

cheers,

'as

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] using different font families with?LaTeX-generated text

2007-05-16 Thread Alexander Schmolck
Darren Dale <[EMAIL PROTECTED]> writes:

> On Monday 14 May 2007 1:29:05 pm Alexander Schmolck wrote:
>> Darren Dale <[EMAIL PROTECTED]> writes:
>> I'd *really* like the ability to ``usepackage`` for various reasons and it
>> would clearly add useful functionality that is not otherwise obtainable.
>>
>> I understand concern about an additional support burden, but couldn't this
>> be handled by explicitly noting that it's unsupported, possibly even
>> printing out an unsubtle warning
[...]
> As far as I'm concerned, being unsupported disqualifies the feature from 
> being 
> included in mpl.

Well, if ever there was a compelling use-case for an undocumented/unsupported
feature it would be this one, I think.

We are talking about something that involves very little implementation effort
(< 5 LOC or so), right? So provided it doesn't result in either an
implementation burden or in additional support requests, why wouldn't you
allow people to obtain functionality, at their own risk, that may be of high
utility to them?

For example, I use a few lower-case bold greek symbols in my work, and I also
want to use them in my plots. Due to some arbitrary braindamage in latex, this
essentially requires a ``\usepackage{bm}`` somewhere in your preamble, and
there are other fairly standard things are as far as I can see impossible to
obtain without (if it doesn't cause portability hassles of the type you
mentioned etc., I think it might actually be worth-while considering to add
things like 'bm' and 'ammssymb' to the default-preamble).

I don't think me and other users editing texmanager by hand or resulting to
some really nasty hacks in order to just extend simple template string being a
better solution (or one that necessarily results in fewer support requests --
"oops, sorry I just noticed I actually screwed around with this file in order
to change my latex-preamble").

It wouldn't even be necessary to add some proper latex_preamble option, as
long as there is some TexManager attribute that's easily enough to modify.

cheers,

'as


-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] using different font families with?LaTeX-generated text

2007-05-17 Thread Alexander Schmolck
"George Nurser" <[EMAIL PROTECTED]> writes:

> Published figures will generally be embedded in text that is Times/
> Palatino etc.
> Computer Modern doesn't look right inside such text.
>
> If it were possible to allow use of the other font packages, it would
> be very useful.

It already is, see e.g.



from the file texmanager.py here are the mappings for the supported font
packages:

font_info = {'new century schoolbook': ('pnc',
r'\renewcommand{\rmdefault}{pnc}'),
'bookman': ('pbk', r'\renewcommand{\rmdefault}{pbk}'),
'times': ('ptm', r'\usepackage{mathptmx}'),
'palatino': ('ppl', r'\usepackage{mathpazo}'),
'zapf chancery': ('pzc', r'\usepackage{chancery}'),
'charter': ('pch', r'\usepackage{charter}'),
'serif': ('cmr', ''),
'sans-serif': ('cmss', ''),
'helvetica': ('phv', r'\usepackage{helvet}'),
'avant garde': ('pag', r'\usepackage{avant}'),
'courier': ('pcr', r'\usepackage{courier}'),
'monospace': ('cmtt', ''),
'computer modern roman': ('cmr', ''),
'computer modern sans serif': ('cmss', ''),
'computer modern typewriter': ('cmtt', '')}


cheers,

'as

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] using different font families with?LaTeX-generated text

2007-05-17 Thread Alexander Schmolck

"George Nurser" <[EMAIL PROTECTED]> writes:

> I didn't realize that!
> Apologies for being ignorant here.
>

No worries, here's a concrete example for selecting Helvetica (and commented
out, Palatino) as default fonts:

from matplotlib.pylab import *
from numpy import *
#rc('font',**dict(family='serif',serif='Palatino'))
rc('font',**{'family':'sans-serif','sans-serif':'Helvetica'})
rc('text', usetex=True)

Note that I've had problems with font-changes being ignored by latex in some
version of matplotlib, but not the latest 0.9 -- if in doubt 
``rm -r ~/.matplotlib/*cache`` and see whether that fixes things.

I've added these two things to 

 

Hope that's OK, otherwise please revert.

cheers,

'as

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] using different font families with?LaTeX-generated text

2007-05-17 Thread Alexander Schmolck
Darren Dale <[EMAIL PROTECTED]> writes:

> On Thursday 17 May 2007 10:08:06 am Alexander Schmolck wrote:
>> "George Nurser" <[EMAIL PROTECTED]> writes:
>> > I didn't realize that!
>> > Apologies for being ignorant here.
>>
>> No worries, here's a concrete example for selecting Helvetica (and
>> commented out, Palatino) as default fonts:
>>
>> from matplotlib.pylab import *
>> from numpy import *
>> #rc('font',**dict(family='serif',serif='Palatino'))
>> rc('font',**{'family':'sans-serif','sans-serif':'Helvetica'})
>> rc('text', usetex=True)
>>
>> Note that I've had problems with font-changes being ignored by latex in
>> some version of matplotlib, but not the latest 0.9 -- if in doubt
>> ``rm -r ~/.matplotlib/*cache`` and see whether that fixes things.
>
> You should also make your rc changes before importing pylab. 

OK, I think it's rather important to ntoe that on the tutorial. I'll do so
later.

> That might be considered a bug, and would take some work to fix.

I've really got to run now but I might look into submitting a patch later; I
think it should'n be that hard: make TexManager._font_config a property that
on setting remembers the contents of the rcParams that are relevant to it and
on accessing reinits itself if it finds they've changed. Does that sound
plausbile to you?

>
>> I've added these two things to
>>
>>  <http://www.scipy.org/Cookbook/Matplotlib/UsingTex>
>>
>> Hope that's OK, otherwise please revert.
>
> Would you mind changing it to use the rcParams dict instead of the rc 
> function? It is clearer that way.

I'd be happy to, but I don't quite understand: Should I also change the other
uses of rc on the page to rcParams? Isn't using rc equivalent except that it
also performs some error checking and alias conversion? Why is it better to
modify rcParams directly?


cheers,

'as

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] using different font families with?LaTeX-generated text

2007-05-18 Thread Alexander Schmolck
Darren Dale <[EMAIL PROTECTED]> writes:

>> Well, if ever there was a compelling use-case for an
>> undocumented/unsupported feature it would be this one, I think.
>
> Alright, svn 3277 lets you add additional commands to the preamble:
>
> text.latex.preamble : \usepackage{bm},\renewcommand{etc...}
>
> See the default matplotlibrc file for more information.
>
> THIS FEATURE IS NOT SUPPORTED. Please don't report problems on the mpl 
> mailing 
> lists without submitting a patch to fix them. 
>
> Alex, please give this a spin. Tell me if it meets your needs, and if it 
> doesnt, send a patch.

Great! Thanks for incorporating this! It fits my needs, but I sent a (mostly
unreleated) patch anyway (against 3278) :)

cheers,

'as

-
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Patch to fix stale tex cache issues [Was: using different font families with?LaTeX-generated text]

2007-05-18 Thread Alexander Schmolck
Darren Dale <[EMAIL PROTECTED]> writes:

> You should also make your rc changes before importing pylab. That might be 
> considered a bug, and would take some work to fix.

I think I've fixed the bug (well, mostly see TODO), as well as a few other
minor bugs:

- ``__init__.py``
  * defaultParams value tuple[0] ought to be the parsed value, as
far as I can see, but the fonts are given as comma-seperated string, which
will result in texmanager treating individual chars as 'fonts'

- ``texmanager.py``
  * 'Computer Modern Sans serif' rather than 'Computer Modern Sans-serif' as
on wiki; I haven't changed it because I don't know which spelling is
desired -- I'd personally prefer two, because it's consistent with the
most common spelling of 'sans-serif' and the spelling elsewhere in MPL
  * condensed `TexManger.__init__` and fixed the undeclare var bug in the
warning; also added check that rcParams['font.*'] is not a string (see
above)
  * `TexManger.get_font_config` now checks that font configuration is in
synch with rcParams and if not re-initialized `self` to recompute it
  * changed ``self._font_config -> self.get_font_config()`` and added it to the 
key
generation for TexManger.get_rgba -- so now every change the relevant
rcParams font entries will now recompute or select the *correct* cached
value (Note I think for get_rgba ._font_config would suffice, but since it
looks like it needs to be modified anyway and .get_font_config is safer I
opted for the latter).
  * added a few consistency checks

This is the first time I've really looked at (and hacked) the MPL code, so my
solution might have issues, I'm certainly not aware of the big picture.
However I'm pretty sure that parts of the patch should be useful and that I've
correctly identified some small bugs.

TODO


A) the wiki page still needs to be corrected; I'm happy to do it, but it would
   be useful to know:
   1. what exactly I should change to ``rcParams`` (all ``rc`` calls?)
   2. how the 'Computer Modern Sans'-'/' 'serif' thing will be resolved
   3. if this patch is likely to be accepted in some form (because then I'll
  also mention that the need to import pylab afterwards will go away in
  svn/future versions)

B) TexManger.get_rgba needs to deal with font-properties other than size to do
   its job properly (i.e. return the *correct* cached text); that means that 2
   places in backend_agg.py will also need changs since it uses insufficient
   info to find the right cached text (no properites). How to do this involves
   making design decisions that I think one of the developers has to take, so
   I didn't do anything about it. I got the impression that just passing
   ``prop.font_family`` together with ``size`` might handle most cases, but I
   have no idea how latex-font-properties are really meant to be handled.

In addition to the patch, I've appended some file to test and demonstrate the
new (hopefully better); behavior (just %run) -- the patch currently is full of
print-DEBUG statements, I've left them in because it makes easier to verify
what's going on and B) still ought to be fixed; they're easy to take remove
(grep DEBUG), but if it's an issue I'm happy to supply the patch without them.

hope this is useful,

'as

from matplotlib.pylab import *
from numpy import *
rc('text', usetex=True)
rc('text', **{'latex.preamble': [r'\usepackage{bm}']})
#figure()
print "Testing that font changes result in cache-invalidation"
print "--"
for font_conf in ({'family':'sans-serif','sans-serif':['Computer Modern Sans serif']},
  {'family':'sans-serif','sans-serif':['avant garde']},
  {'family':'sans-serif','sans-serif':['Helvetica']},


  dict(family='serif',serif=['Palatino']),
  dict(family='serif',serif=['Times']),
  dict(family='serif',serif=['Bookman']),
  dict(family='serif',serif=['Computer Modern Roman']),  
  ): 
clf()
rc('font',**font_conf)
title(font_conf)
text(0,0, r'I will $\bm{g\epsilon\tau}$ RECOMPUTED correctly!',
 fontsize=25,verticalalignment='center',horizontalalignment='center')
axis([-1, 1, -1, 1])
show(); raw_input('Press Return')

print "Testing that illegal font-specs get detected"
print ""
raw_input('RETURN')
clf()
# should throw
try:
rc('text', **{'latex.preamble': r'\usepackage{bm}'})
text(0,0, 'I will get RECOMPUTED correctly!',
  fontsize=25,verticalalignment='center',horizontalalignment='center')
show();
except AssertionError, msg:
print "-- SUCCESS: DETECTED CORRUPTION --", msg
rc('text', **{'latex.preamble': [r'\usepackage{bm}']})
else:
raise "FAILED"
try:
rc('font',**{'family':'sans-serif','sans-serif':'Helvetica'})
text(0,0, 'I will get RECOMPUTED correctly!',

[Matplotlib-users] embedding matplotlib in C++ and closing the matplotlib window

2007-10-11 Thread Alexander Schmolck
Hi,

I'm using matplotlib in a C++ app (with a qt4 gui), by embedding python with
boost::python. The C++ app calls Py_Initialize(), init_myplottingmodule(), and
boost::python::import("matplotlib.pylab") once on startup and certain GUI
events then fire up a matplotlib window via calls like this one:

// simplified version
void plotCurve(){
clf();
title("Diagonal line plot");
double O1[] = {0,1};
plot(std::vector(O1,O1+2), std::vector(O1,O1+2), "b:");
show();
}

Although this does sort of work, it doesn't work quite right. Specifically on
clicking on the close button of the window, bad things frequently happen. For
example, the first close seems to work, but subsequent attempts to close newly
opened plots just zombify the window (it no longer repaints automatically but
stays open; replots happen to that same window, i.e. the one that was opened
second).

Now I'm somewhat aware of all the nastiness of different event loops, the
heroic efforts of ipython to make matplotlib work nicely interactively without
blocking the REPL, but somehow I would have (naively) thought that all that
work was just needed to avoid blocking. For the code above, blocking till the
window would be closed is perfectly fine. Indeed that's what happens if I try
something equivalent in the plain python shell (outside the C++ app).

Any idea about the likely cause of the problem and what might be the simplest
way to get it to work as expected (similar symptoms appear w/ matplotlib
0.87.7 and 0.91 under linux and osx)?

cheers,

'as

-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users