Hi Goyo and Darren,

thanks for pointing out the rcParams solution! For the time being,
this seems an OK approach. I'd like to use the automatic solution,
though, but this does not seem to work:

import matplotlib.pyplot as plt
import matplotlib.transforms as mtransforms
import numpy,pylab,matplotlib.ticker as mtick

x = numpy.linspace(0,10,1000)
y = numpy.exp(x)

pylab.rcdefaults()

def on_draw(event):
  bboxes = []
  for label in labels:
    bbox = label.get_window_extent()
    # the figure transform goes from relative coords->pixels and we
    # want the inverse of that
    bboxi = bbox.inverse_transformed(fig.transFigure)
    bboxes.append(bboxi)
  # this is the bbox that bounds all the bboxes, again in relative
  # figure coords
  bbox = mtransforms.Bbox.union(bboxes)
  if fig.subplotpars.left < bbox.width:
    # we need to move it over
    fig.subplots_adjust(left=1.1*bbox.width) # pad a little
    fig.canvas.draw()
  return False

fig = pylab.figure(figsize=(5,3))
ax = fig.add_subplot(111)
ax.set_yscale('log')
ax.yaxis.set_major_formatter(mtick.FormatStrFormatter('%d'))
ax.set_xlabel('asdf')
ax.set_ylabel('qwer')
ax.plot(x,y)
labels = ax.get_yticklabels()
fig.canvas.mpl_connect('draw_event', on_draw)
fig.savefig('example_mpl-ticker_2')

2011/2/25 Darren Dale <dsdal...@gmail.com>:
> On Tue, Feb 22, 2011 at 4:23 AM, Daniel Mader
> <danielstefanma...@googlemail.com> wrote:
>> Hi,
>>
>> there has been a similar question recently but I couldn't figure out
>> if or how this is solved:
>>
>> I'd like to reduce the figure size so that I can add it to a LaTeX
>> document without scaling (PDF output with LaTeX font rendering). For
>> that, I need to adapt the font sizes, too.
>>
>> Unfortunately, the canvas is not properly scaled so that the axis
>> labels and the possibly the tick marks are cut off.
>>
>> Is this a bug, feature, design flaw? How can I properly work around
>> it, i.e. reduce the graph automatically for a given figsize/font size
>> combination so that everything fits on the figure?
>>
>> An example follows to demonstrate, thanks in advance
>
> I use matplotlib for this purpose pretty frequently. A few tricks:
>
> from http://matplotlib.sourceforge.net/users/customizing.html :
> # note that font.size controls default text sizes.  To configure
> # special text sizes tick labels, axes, labels, title, etc, see the rc
> # settings for axes and ticks. Special text sizes can be defined
> # relative to font.size, using the following values: xx-small, x-small,
> # small, medium, large, x-large, xx-large, larger, or smaller
>
> # specify the figure canvas size, in inches
> figure(figsize=(3.4, 4))
>
> # place the axes in the figure window
> # specifying (left, bottom, width, height) as fraction of figure size
> # adjust those positions to make enough room for tick and axis labels
> axes([0.15, 0.12, 0.8, 0.83])
>
> Specify the dpi for you screen, so the figure rendered on your screen
> is the correct size. This is figure.dpi, best to set it in
> matplotlibrc.
>
> Darren
>



-- 
Zugallistr. 11/14
5020 Salzburg
M_at +43 699 10 54 54 53
T_at +43 662 841635
M_de +49 179 2300317
E danielstefanma...@googlemail.com

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to