Skip to content

Commit 4264bc7

Browse files
committed
added auto subplots adj faq
svn path=/trunk/matplotlib/; revision=5596
1 parent 9403806 commit 4264bc7

File tree

6 files changed

+175
-52
lines changed

6 files changed

+175
-52
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jdh_doc_snapshot:
3939
rm -rf build;\
4040
python make.py clean;\
4141
svn up;\
42-
python make.py html latex sf;
42+
python make.py html latex sf sfpdf;
4343

4444

4545

doc/faq/howto_faq.rst

+34
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,40 @@ where all values are in fractional (0 to 1) coordinates. See
5454
`axes_demo.py <http://matplotlib.sf.net/examples/axes_demo.py>`_ for
5555
an example of placing axes manually.
5656

57+
.. _howto-auto-adjust:
58+
59+
How do I automatically make room for my tick labels?
60+
====================================================
61+
62+
In most use cases, it is enought to simpy change the subplots adjust
63+
parameters as described in :ref:`howto-subplots-adjust`. But in some
64+
cases, you don't know ahead of time what your tick labels will be, or
65+
how large they will be (data and labels outside your control may be
66+
being fed into your graphing application), and you may need to
67+
automatically adjust your subplot parameters based on the size of the
68+
tick labels. Any :class:`matplotlib.text.Text` instance can report
69+
its extent in window coordinates (a negative x coordinate is outside
70+
the window), but there is a rub.
71+
72+
The :class:`matplotlib.backend_bases.RendererBase` instance, which is
73+
used to calculate the text size, is not known until the figure is
74+
drawn (:meth:`matplotlib.figure.Figure.draw`). After the window is
75+
drawn and the text instance knows its renderer, you can call
76+
:meth:`matplotlib.text.Text.get_window_extent``. One way to solve
77+
this chicken and egg problem is to wait until the figure is draw by
78+
connecting
79+
(:meth:`matplotlib.backend_bases.FigureCanvasBase.mpl_connect`) to the
80+
"on_draw" signal (:class:`~matplotlib.backend_bases.DrawEvent`) and
81+
get the window extent there, and then do something with it, eg move
82+
the left of the canvas over; see :ref:`event-handling-tutorial`.
83+
84+
Here is a recursive, iterative solution that will gradually move the
85+
left of the subplot over until the label fits w/o going outside the
86+
figure border (requires matplotlib 0.98)
87+
88+
.. plot:: auto_subplots_adjust.py
89+
:include-source:
90+
5791
.. _howto-ticks:
5892

5993
How do I configure the tick linewidths?

doc/glossary/index.rst

+100-35
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,138 @@ Glossary
88
.. glossary::
99

1010
AGG
11-
The Anti-Grain Geometry rendering engine, capable of rendering
12-
high-quality images.
11+
The Anti-Grain Geometry (`Agg <http://antigrain.com>`_) rendering engine, capable of rendering
12+
high-quality images
1313

1414
Cairo
15-
The Cairo graphics engine
15+
The `Cairo graphics <http://cairographics.org>`_ engine
1616

1717
EPS
18-
Encapsulated Postscript
18+
Encapsulated Postscript (`EPS <http://en.wikipedia.org/wiki/Encapsulated_PostScript>`_)
1919

2020
FLTK
21-
FLTK (pronounced "fulltick") is a cross-platform C++ GUI toolkit for
21+
`FLTK <http://www.fltk.org/>`_ (pronounced "fulltick") is a cross-platform C++ GUI toolkit for
2222
UNIX/Linux (X11), Microsoft Windows, and MacOS X
2323

24+
freetype
25+
`freetype <http://www.freetype.org/>`_ is a font rasterization
26+
library used by matplotlib which supports TrueType, Type 1, and
27+
OpenType fonts.
28+
29+
2430
GDK
2531
The Gimp Drawing Kit for GTK+
2632

2733
GTK
28-
The GTK graphical user interface library
34+
The GIMP Toolkit (`GTK <http://www.gtk.org/>`_) graphical user interface library
2935

3036
JPG
31-
A compression method and file format for photographic images
37+
The Joint Photographic Experts Group (`JPEG
38+
<http://en.wikipedia.org/wiki/Jpeg>`_) compression method and
39+
file format for photographic images
40+
41+
numpy
42+
`numpy <http://numpy.scipy.org>`_ is the standard numerical
43+
array library for python, the successor to Numeric and numarray.
44+
numpy provides fast operations for homogeneous data sets and
45+
common mathematical operations like correlations, standard
46+
deviation, fourier transforms, and convolutions.
3247

3348
PDF
34-
Adobe's Portable Document Format
49+
Adobe's Portable Document Format (`PDF <http://en.wikipedia.org/wiki/Portable_Document_Format>`_)
3550

3651
PNG
37-
PNG stands for Portable Network Graphics, a raster graphics format that
38-
employs lossless data compression which is more suitable for line art
39-
than the lossy jpg format. Unlike the gif format, png is not encumbered
40-
by requirements for a patent license.
52+
Portable Network Graphics (`PNG
53+
<http://en.wikipedia.org/wiki/Portable_Network_Graphics>`_), a raster graphics format
54+
that employs lossless data compression which is more suitable
55+
for line art than the lossy jpg format. Unlike the gif format,
56+
png is not encumbered by requirements for a patent license.
4157

4258
PS
43-
Postscript
59+
Postscript (`PS <http://en.wikipedia.org/wiki/PostScript>`_) is a
60+
vector graphics ASCII text language widely used in printers and
61+
publishing. Postscript was developerd by adobe systems and is
62+
starting to show its age: for example is does not have an alpha
63+
channel. PDF was designed in part as a next-generation document
64+
format to replace postscript
65+
66+
pyfltk
67+
`pyfltk <http://pyfltk.sourceforge.net/>`_ provides python
68+
wrappers for the :term:`FLTK` widgets library for use with
69+
FLTKAgg
70+
71+
pygtk
72+
`pygtk <http://www.pygtk.org/>`_ provides python wrappers for
73+
the :term:`GTK` widgets library for use with the GTK or GTKAgg
74+
backend. Widely used on linux, and is often packages as
75+
'python-gtk2'
76+
77+
pyqt
78+
`pyqt <http://wiki.python.org/moin/PyQt>`_ provides python
79+
wrappers for the :term:`Qt` widgets library and is requied by
80+
the matplotlib QtAgg and Qt4Agg backends. Widely used on linux
81+
and windows; many linux distributions package this as
82+
'python-qt3' or 'python-qt4'.
83+
84+
python
85+
`python <http://python.org>`_ is an object oriented interpreted
86+
language widely used for scripting, application development, web
87+
application servers, scientific computing and more.
4488

4589
Qt
46-
Qt is a cross-platform application framework for desktop and embedded
47-
development.
90+
`Qt <http://trolltech.com/products/qt/>`__ is a cross-platform
91+
application framework for desktop and embedded development.
4892

4993
Qt4
50-
Qt4 is the most recent version of Qt cross-platform application framework
51-
for desktop and embedded development.
94+
`Qt4 <http://trolltech.com/products/qt/>`__ is the most recent
95+
version of Qt cross-platform application framework for desktop
96+
and embedded development.
5297

5398
raster graphics
54-
Raster graphics, or bitmaps, represent an image as an array of pixels
55-
which is resolution dependent. Raster graphics are generally most
56-
practical for photo-realistic images, but do not scale easily without
57-
loss of quality. See `raster graphics <http://en.wikipedia.org/wiki/Raster_graphics>`_
99+
`Raster graphics
100+
<http://en.wikipedia.org/wiki/Raster_graphics>`_, or bitmaps,
101+
represent an image as an array of pixels which is resolution
102+
dependent. Raster graphics are generally most practical for
103+
photo-realistic images, but do not scale easily without loss of
104+
quality.
58105

59106
SVG
60-
The Scalable Vector Graphics format.
107+
The Scalable Vector Graphics format (`SVG
108+
<http://en.wikipedia.org/wiki/Svg>`_). An XML based vector
109+
graphics format supported by many web browsers.
61110

62111
TIFF
63-
Tagged Image File Format
112+
Tagged Image File Format (`TIFF
113+
<http://en.wikipedia.org/wiki/Tagged_Image_File_Format>`_) is a
114+
file format for storing images, including photographs and line
115+
art.
64116

65117
Tk
66-
Tk is a graphical user interface for Tcl and many other dynamic
67-
languages. It can produce rich, native applications that run unchanged
68-
across Windows, Mac OS X, Linux and more.
118+
`Tk <http://www.tcl.tk/>`_ is a graphical user interface for Tcl
119+
and many other dynamic languages. It can produce rich, native
120+
applications that run unchanged across Windows, Mac OS X, Linux
121+
and more.
122+
123+
vector graphics
124+
`vector graphics
125+
<http://en.wikipedia.org/wiki/Vector_graphics>`_ use geometrical
126+
primitives based upon mathematical equations to represent images
127+
in computer graphics. Primitives can include points, lines,
128+
curves, and shapes or polygons. Vector graphics are scalable,
129+
which means that they can be resized without suffering from
130+
issues related to inherent resolution like are seen in raster
131+
graphics. Vector graphics are generally most practical for
132+
typesetting and graphic design applications.
133+
134+
wxpython
135+
`wxpython <http://www.wxpython.org/>`_ provides python wrappers
136+
for the :term:`wxWidgets` library for use with the WX and WXAgg
137+
backends. Widely used on linux, OS-X and windows, it is often
138+
packaged by linux distributions as 'python-wxgtk'
69139

70140
wxWidgets
71-
A cross-platform GUI and tools library for GTK, MS Windows, and MacOS.
141+
`WX <http://www.wxwidgets.org/>`_ is cross-platform GUI and
142+
tools library for GTK, MS Windows, and MacOS. It uses native
143+
widgets for each operating system, so applications will have the
144+
look-and-feel that users on that operating system expect.
72145

73-
vector graphics
74-
The use of geometrical primitives based upon mathematical equations to
75-
represent images in computer graphics. Primitives can include points,
76-
lines, curves, and shapes or polygons. Vector graphics are scalable,
77-
which means that they can be resized without suffering from issues
78-
related to inherent resolution like are seen in raster graphics. Vector
79-
graphics are generally most practical for typesetting and graphic design
80-
applications. See `vector graphics <http://en.wikipedia.org/wiki/Vector_graphics>`_

doc/make.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ def check_build():
1717
def sf():
1818
'push a copy to the sf site'
1919
os.system('cd build; rsync -avz html jdh2358@matplotlib.sf.net:/home/groups/m/ma/matplotlib/htdocs/doc/ -essh')
20-
os.system('cd build/latex; scp Matplotlib.pdf jdh2358@matplotlib.sf.net:/home/groups/m/ma/matplotlib/htdocs/doc/')
20+
21+
def sfpdf():
22+
'push a copy to the sf site'
23+
24+
#os.system('cd build/latex; scp Matplotlib.pdf jdh2358@matplotlib.sf.net:/home/groups/m/ma/matplotlib/htdocs/doc/')
2125

2226
def figs():
2327
os.system('cd users/figures/ && python make.py')
@@ -73,6 +77,7 @@ def all():
7377
'latex':latex,
7478
'clean':clean,
7579
'sf':sf,
80+
'sfpdf':sfpdf,
7681
'all':all,
7782
}
7883

doc/pyplots/auto_subplots_adjust.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import matplotlib.pyplot as plt
2+
3+
fig = plt.figure()
4+
ax = fig.add_subplot(111)
5+
ax.plot(range(10))
6+
ax.set_yticks((2,5,7))
7+
labels = ax.set_yticklabels(('really, really, really', 'long', 'labels'))
8+
9+
def on_draw(event):
10+
for label in labels:
11+
bbox = label.get_window_extent()
12+
if bbox.xmin<0:
13+
fig.subplots_adjust(left=1.1*fig.subplotpars.left)
14+
fig.canvas.draw()
15+
break
16+
17+
fig.canvas.mpl_connect('draw_event', on_draw)
18+
19+
plt.show()

doc/users/installing.rst

+15-15
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ installing matplotlib. Windows users only need the first two (python
1414
and numpy) since the others are built into the matplotlib windows
1515
installers available for download at the sourceforge site.
1616

17-
python 2.4 (or later but not python3)
18-
matplotlib requires python 2.4 or later
17+
:term:`python` 2.4 (or later but not python3)
18+
matplotlib requires python 2.4 or later (`download <http://www.python.org/download/>`__)
1919

20-
numpy 1.1 (or later)
21-
array support for python
20+
:term:`numpy` 1.1 (or later)
21+
array support for python (`download <http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103>`__)
2222

2323
libpng 1.1 (or later)
24-
library for loading and saving PNG files. libpng requires zlib. If
24+
library for loading and saving :term:`PNG` files (`download <http://www.libpng.org/pub/png/libpng.html>`__). libpng requires zlib. If
2525
you are a windows user, you can ignore this since we build support
26-
into the matplotlib single click installer.
26+
into the matplotlib single click installer
2727

28-
freetype 1.4 (or later)
28+
:term:`freetype` 1.4 (or later)
2929
library for reading true type font files. If you are a windows
3030
user, you can ignore this since we build support into the
3131
matplotlib single click installer.
@@ -37,25 +37,25 @@ matplotlib with a user interface toolkit. See
3737
:ref:`what-is-a-backend` for more details on the optional matplotlib
3838
backends and the capabilities they provide
3939

40-
tk 8.3 or later
40+
:term:`tk` 8.3 or later
4141
The TCL/Tk widgets library used by the TkAgg backend
4242

43-
pyqt 3.1 or later
43+
:term:`pyqt` 3.1 or later
4444
The Qt3 widgets library python wrappers for the QtAgg backend
4545

46-
pyqt 4.0 or later
46+
:term:`pyqt` 4.0 or later
4747
The Qt4 widgets library python wrappersfor the Qt4Agg backend
4848

49-
pygtk 2.2 or later
49+
:term:`pygtk` 2.2 or later
5050
The python wrappers for the GTK widgets library for use with the GTK or GTKAgg backend
5151

52-
wxpython 2.6 or later
52+
:term:`wxpython` 2.6 or later
5353
The python wrappers for the wx widgets library for use with the WXAgg backend
5454

55-
wxpython 2.8 or later
55+
:term:`wxpython` 2.8 or later
5656
The python wrappers for the wx widgets library for use with the WX backend
5757

58-
pyfltk 1.0 or later
58+
:term:`pyfltk` 1.0 or later
5959
The python wrappers of the FLTK widgets library for use with FLTKAgg
6060

6161
**Required libraries that ship with matplotlib**
@@ -65,7 +65,7 @@ subversion, you can ignore this section. This is useful for matplotlib
6565
developers and packagers who may want to disable the matplotlib
6666
version and ship a packaged version.
6767

68-
agg2.4
68+
:term:`agg` 2.4
6969
The antigrain C++ rendering engine
7070

7171
pytz 2007g or later

0 commit comments

Comments
 (0)