From: Meesters, C. <mee...@un...> - 2005-05-27 17:09:17
Attachments:
test.jpg
|
Hi,=20 It's me again ... I still do not find my way out of the problem on how I = can apply a format to the numbering of an axis. I am using the WXAgg = backend and this is my code: font =3D FontProperties() self.font =3D font.copy() self.font.set_size('x-small') self.font.set_family('serif') self.font.set_style('normal') self.font.set_variant('normal') self.font.set_weight('light') <snip>and then a function plot_data: def plot_data(self): <snip> a =3D self.fig.add_subplot(111) a.grid(self.g) =09 for x,y in zip(self.active_datasets,linestyles): if len(self.datasets)=3D=3D1: a.set_title('Spatial Distribution of = %s' % x.attributes['name'], fontproperties=3Dself.font, = horizontalalignment=3D'right') if self.log_intensity: a.semilogy(x.ichannel,x.intensity,'k',y) a.set_xlim([0,len(x.ichannel)]) a.set_ylabel(r'$log_{10} \rm{(Intensity [counts])}$', = fontproperties=3Dself.font) a.set_xlabel(r'$\rm{channels}$', = fontproperties=3Dself.font) <snip> Now, how can I apply the font to the subplot? In order to illustrate the = problem a little bit better, I attached a part of a screen shot. Here, with just one single subplot there is actually no problem and the = plot would look absolutely stunning witht the default font. But with = more than one subplot in the panel there is just not enough space to = display all labels and the numbering on my screen. I guess the solution is not half as complicated than the things I've = tried. But since it is not really obvious to me, I am willing to = contribute an example to this topic if there is not already one. Are = there guidelines on how to file examples? Regards, Christian |
From: Ken M. <mc...@ii...> - 2005-05-27 17:29:02
|
Meesters, Christian wrote: > It's me again ... I still do not find my way out of the problem on how I can > apply a format to the numbering of an axis. I am using the WXAgg backend and > this is my code: It sounds like you tring to change the formatting of the tick labels of the axes. I believe that the RC parameter `tick.labelsize' will do the trick if this is all you need. There are doubtless a slew of other tick-related options. If you're trying to do something more complicated, like setup complicated font properties for the labels, the following approach might work. def fontify_ticks(axes, fp): xticks = axes.xaxis.get_major_ticks() + axes.xaxis.get_minor_ticks() yticks = axes.yaxis.get_major_ticks() + axes.yaxis.get_minor_ticks() for t in xticks + yticks: t.label1.set_fontproperties(fp) # outer/upper tick label t.label2.set_fontproperties(fp) # inner/lower tick label I hope this helps. Ken |
From: John H. <jdh...@ac...> - 2005-05-27 17:32:31
|
>>>>> "Meesters," == Meesters, Christian <mee...@un...> writes: Meesters> Hi, It's me again ... I still do not find my way out of Meesters> the problem on how I can apply a format to the Meesters> numbering of an axis. I am using the WXAgg backend and Meesters> this is my code: To apply a "default font" for the entire figure, you can use the rc params -- see http://matplotlib.sf.net/.matplotlibrc, especially the font.*, axes.* and tick.* settings from matplotlib import rc from pylab import figure, show rc('font', weight='bold', style='italics') rc('axes', labelsize=25) rc('tick', labelsize=14) fig = figure() ax = fig.add_subplot(111) ax.plot(range(10)) ax.set_xlabel('hi') ax.set_ylabel('bye') ax.set_title('easy as 1-2-3') show() You can also customize the default tick labels sizes individually. I already noted that for the xlabel, ylabel and title you can use kwargs, eg ax.set_xlabel('hi', fontsize='smaller') and so on. For the tick labels, you will need to get a list of the tick label Text instances you want to customize labels = ax.get_xticklabels() You can call any of the text setter methods on these labels, which are detailed here http://matplotlib.sourceforge.net/matplotlib.text.html#Text For example, you can set the fontsize or fontproperty with for label in labels: label.set_fontsize(mysize) for label in labels: label.set_fontproperties(fp) A lot of the methods like set_fontsize are historical artifacts from before we had font properties, and they just forward the call to the property If you want finer grained control over the major and minor ticks, or different customizations for the top and bottom ticks (on the xaxis the top ticks are normally off but you can turn them on) you can do that too, but it is a little more work # ditto for get_minor_ticks ticks = ax.xaxis.get_major_ticks() majLabelsLower = [tick.label1 for tick in ticks] majLabelsUpper = [tick.label2 for tick in ticks] and then call the setter methods on these as above. Hope this helps, JDH |
From: Christian M. <mee...@un...> - 2005-05-28 11:24:14
|
Hi, Thanks John and Ken for your detailed replies. They came almost immediately, but since I'm 6-7 hours ahead of you and the weekend was approaching this answer took a bit longer ... Anyway, now everything is working - finally I've got it. In contrast to your advise, John, I rather don't change the rc-file, for this not such a good idea if one wants to distribute the software at some point among colleagues. May I still add a different question? As you know I'm using the WXAgg backend (at least in some of my scripts) and embedded essentially everything like in the example scripts: class SAXS_wx(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self,None,-1,"SPlot") <snip> self.fig = Figure(figsize=(5,4),dpi=100) self.axes = self.fig.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.fig) self.parent = self.canvas.GetParent() self.canvas.mpl_connect('motion_notify_event',self.mouse_move) sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = sizer sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW|wx.EXPAND) self.add_splot_toolbar() self.SetSizer(self.sizer) self.Fit() Now, changing the figsize parameter has absolutely no effect on the canvas size whatsoever. Does anybody know how to change the figure size? Currently I only get a beautifully, tiny window every user needs to expand by hand ... Once more for the record: I'm stuck with matplotlib 0.71 on Panther (OS X 10.3) with Apple's framework Python 2.3 for a while. Thanks, Christian |
From: Ken M. <mc...@ii...> - 2005-05-28 15:19:28
|
On May 28, 2005, at 6:24 AM, Christian Meesters wrote: > Now, changing the figsize parameter has absolutely no effect on the > canvas size whatsoever. Does anybody know how to change the figure > size? Currently I only get a beautifully, tiny window every user needs > to expand by hand ... I have been unable to reproduce this behavior using matplotlib 0.72 under OS X 10.3.9 with wxPython 2.6.0.0. What version of wxPython are you running? Ken |
From: Christian M. <mee...@un...> - 2005-05-28 23:51:54
|
On 28 May 2005, at 17:20, Ken McIvor wrote: > On May 28, 2005, at 6:24 AM, Christian Meesters wrote: >> Now, changing the figsize parameter has absolutely no effect on the >> canvas size whatsoever. Does anybody know how to change the figure >> size? Currently I only get a beautifully, tiny window every user >> needs to expand by hand ... > > I have been unable to reproduce this behavior using matplotlib 0.72 > under OS X 10.3.9 with wxPython 2.6.0.0. What version of wxPython are > you running? > > Ken > Hm, 2.5.3.1. I know it's time to update my system, but this will have to wait for a while. I need to coordinate several modules / versions. Anyway, thanks for looking into this. If it is really related to my wx version, there is no solution for me now. But then again, if I move my stuff to an updated Linux system soon, there should be no problem (at least not with wx ...). Thanks, Christian |
From: John H. <jdh...@ac...> - 2005-05-29 01:21:59
|
>>>>> "Christian" == Christian Meesters <mee...@un...> writes: Christian> Hm, 2.5.3.1. I know it's time to update my system, but Christian> this will have to wait for a while. I need to Christian> coordinate several modules / versions. The figsize parameter is being respected for me on OSX 10.3 with matplotlib 0.80 and wx 2.5.4.1. Not sure if it is a matplotlib version or wxpythnon version that is causing your problems. I looked through the CHANGELOG to see if there were any obvious changes between 0.71 and 0.80 that indicated a bugfix for wx figure sizing, but didn't see any. You might also check the commit notes for backend_wx or backend_wxagg. JDH |
From: Matt N. <new...@ca...> - 2005-05-29 03:08:41
|
Christian, I don't recall seeing this behavior of absurdly small figures and no response to figsize argement, even using wxPython 2.5.3 on Mac OS X (though, admittedly I'm using matplotlib 0.8). The script below works fine for me, and changing the figsize argument to Figure() does change the figure size. Does this work for you -- you might have to change the wxversion.select() line, or just comment it out. If this works for you, can you post a simple, self-contained script that fails? Cheers, --Matt #!/usr/bin/env python import wxversion wxversion.select('2.5.3-mac-ansi') import wx print 'using wxPython version ', wx.__version__ import matplotlib matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.figure import Figure class SimpleFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None,-1, 'wx Matplotlib Frame') self.figure = Figure(figsize=(5,3),dpi=96) self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW|wx.EXPAND) self.SetSizer(self.sizer) self.Fit() class App(wx.PySimpleApp): def OnInit(self): frame = SimpleFrame() frame.Show(True) return True app = App(0) app.MainLoop() ############## |
From: Christian M. <mee...@un...> - 2005-05-30 10:36:44
|
Thanks, Matt! It took me a while to understand this: Your mini-script worked like expected. I could change the size easily. But my own program still didn't react to any change in the figsize parameter. However, as soon as I took out the toolbar, everything was fine! There seems to be a conflict with the sizers, which I could not solve until now. I will dive into this and post an update, if I find a solution. Cheers Christian On 29 May 2005, at 05:08, Matt Newville wrote: > Christian, > > I don't recall seeing this behavior of absurdly small figures > and no response to figsize argement, even using wxPython 2.5.3 > on Mac OS X (though, admittedly I'm using matplotlib 0.8). > > The script below works fine for me, and changing the figsize > argument to Figure() does change the figure size. Does this work > for you -- you might have to change the wxversion.select() line, > or just comment it out. If this works for you, can you post a > simple, self-contained script that fails? > > Cheers, > > --Matt > |
From: Matt N. <new...@ca...> - 2005-05-30 23:02:37
|
Christian, Hmm, it does sound like there might be a sizer conflict. Do you get the tiny-figurecanvase behavior with the embedding_in_wx*.py examples?? These have toolbars, but start off with reasonable sizes, and respond to resizing ok for me. --Matt |
From: Christian M. <mee...@un...> - 2005-05-31 07:37:41
|
One - hopefully final - update: As some might remember my original snippet was this: class SAXS_wx(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self,None,-1,"SPlot") <snip> self.fig = Figure(figsize=(5,4),dpi=100) self.axes = self.fig.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.fig) self.parent = self.canvas.GetParent() self.canvas.mpl_connect('motion_notify_event',self.mouse_move) sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = sizer sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW|wx.EXPAND) self.add_splot_toolbar() self.SetSizer(self.sizer) self.Fit() The problem was that changing the figsize parameter had no effect on the frame size. Changing to self.SetSizer(self.sizer) self.Fit() self.add_splot_toolbar() solved the problem, where add_splot_toolbar() - a toolbar function very much like the 2nd toolbar in the wx examples - is added only just after arranging the sizer. I was unable to arrange the toolbar with the sizer - regardless of the sizer and the layout I used. Hence the problem is definitively wx-related, possibly together with a problem in Panther's framework, since I find the old sequence of commands in the examples and the misbehaving canvas there as well. May I suggest adding a comment in the examples for OSX users so that they are aware of a possible conflict there? Thanks once more, Christian |
From: John H. <jdh...@ac...> - 2005-05-31 13:37:55
|
>>>>> "Christian" == Christian Meesters <mee...@un...> writes: Christian> solved the problem, where add_splot_toolbar() - a Christian> toolbar function very much like the 2nd toolbar in the Christian> wx examples - is added only just after arranging the Christian> sizer. I was unable to arrange the toolbar with the Christian> sizer - regardless of the sizer and the layout I Christian> used. Hence the problem is definitively wx-related, Christian> possibly together with a problem in Panther's Christian> framework, since I find the old sequence of commands in Christian> the examples and the misbehaving canvas there as well. Christian> May I suggest adding a comment in the examples for OSX Christian> users so that they are aware of a possible conflict Christian> there? Would you be willing to add the comments to one or more of the embedding_in_wx*.py examples and send them to me? Thanks! JDH |