Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4be9af

Browse files
committed
added backend bases api
svn path=/trunk/matplotlib/; revision=5463
1 parent 728dc3f commit e4be9af

7 files changed

Lines changed: 403 additions & 261 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
2008-06-10 Bar now applies the label only to the frist patch, and
2-
sets _nolegend_ for the other patch labels. This let's
3-
autolegend work as expected for hist and bar
1+
2008-06-10 Bar now applies the label only to the first patch only, and
2+
sets '_nolegend_' for the other patch labels. This lets
3+
autolegend work as expected for hist and bar - see
4+
https://sourceforge.net/tracker/index.php?func=detail&aid=1986597&group_id=80706&atid=560720
5+
JDH
46

57
2008-06-10 Fix text baseline alignment bug. [ 1985420 ] Repair of
68
baseline alignment in Text._get_layout. Thanks Stan West -

doc/api/backend_api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*******************
2+
matplotlib backends
3+
*******************
4+
5+
6+
:mod:`matplotlib.backend_bases`
7+
================================
8+
9+
.. automodule:: matplotlib.backend_bases
10+
:members:
11+
:undoc-members:

doc/api/index.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
:Release: |version|
88
:Date: |today|
99

10-
Introduction to developer's guide here **TODO**.
11-
1210
.. toctree::
1311

1412
artist_api.rst
1513
axes_api.rst
1614
pyplot_api.rst
17-
15+
backend_api.rst

doc/users/event_handling.rst

Lines changed: 85 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ code across the different user interfaces. Although the event
1313
handling API is GUI neutral, it is based on the GTK model, which was
1414
the first user interface matplotlib supported. The events that are
1515
triggered are also a bit richer vis-a-vis matplotlib than standard GUI
16-
events, including information like which Axes the event occurred in.
17-
The events also understand the matplotlib coordinate system, and
18-
report event locations in both pixel and data coordinates.
16+
events, including information like which :class:`matplotlib.axes.Axes`
17+
the event occurred in. The events also understand the matplotlib
18+
coordinate system, and report event locations in both pixel and data
19+
coordinates.
1920

2021
.. _event-connections:
2122

@@ -24,8 +25,9 @@ Event connections
2425

2526
To receive events, you need to write a callback function and then
2627
connect your function to the event manager, which is part of the
27-
FigureCanvas. Here is a simple example that prints the location of
28-
the mouse click and which button was pressed::
28+
:class:`~matplotlib.backend_bases.FigureCanvasBase`. Here is a simple
29+
example that prints the location of the mouse click and which button
30+
was pressed::
2931

3032
fig = plt.figure()
3133
ax = fig.add_subplot(111)
@@ -37,61 +39,63 @@ the mouse click and which button was pressed::
3739

3840
cid = fig.canvas.mpl_connect('button_press_event', onclick)
3941

40-
The FigureCanvas method mpl_connect returns a connection id which is
41-
simply an integer. When you want to disconnect the callback, just
42-
call::
42+
The ``FigureCanvas`` method
43+
:meth:`~matplotlib.backend_bases.FigureCanvasBase.mpl_connect` returns
44+
a connection id which is simply an integer. When you want to
45+
disconnect the callback, just call::
4346

4447
fig.canvas.mpl_disconnect(cid)
4548

4649
Here are the events that you can connect to, the class instances that
4750
are sent back to you when the event occurs, and the event descriptions
4851

4952

50-
===================== =========== ===================================
51-
Event name Class Description
52-
===================== =========== ===================================
53-
button_press_event MouseEvent mouse button is pressed
54-
button_release_event MouseEvent mouse button is released
55-
draw_event DrawEvent canvas draw
56-
key_press_event KeyEvent key is pressed
57-
key_release_event KeyEvent key is released
58-
motion_notify_event MouseEvent mouse motion
59-
pick_event PickEvent an object in the canvas is selected
60-
resize_event ResizeEvent figure canvas is resized
61-
scroll_event MouseEvent mouse scroll wheel is rolled
62-
===================== =========== ===================================
53+
======================= ======================================================================================
54+
Event name Class and description
55+
======================= ======================================================================================
56+
'button_press_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is pressed
57+
'button_release_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is released
58+
'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw
59+
'key_press_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is pressed
60+
'key_release_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is released
61+
'motion_notify_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse motion
62+
'pick_event' :class:`~matplotlib.backend_bases.PickEvent` - an object in the canvas is selected
63+
'resize_event' :class:`~matplotlib.backend_bases.ResizeEvent` - figure canvas is resized
64+
'scroll_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse scroll wheel is rolled
65+
======================= ======================================================================================
6366

6467
.. _event-attributes:
6568

6669
Event attributes
6770
================
6871

6972
All matplotlib events inherit from the base class
70-
matplotlib.backend_bases.Event, which store the attributes
73+
:class:`matplotlib.backend_bases.Event`, which store the attributes
7174

7275
=============== =================================================
7376
Event attribute Description
7477
=============== =================================================
75-
name the event name
76-
canvas the FigureCanvas instance generating the event
77-
guiEvent the GUI event that triggered the matplotlib event
78+
``name`` the event name
79+
``canvas`` the FigureCanvas instance generating the event
80+
``guiEvent`` the GUI event that triggered the matplotlib event
7881
=============== =================================================
7982

8083
The most common events that are the bread and butter of event handling
8184
are key press/release events and mouse press/release and movement
82-
events. The KeyEvent and MouseEvent classes that handle these events
83-
are both derived from the LocationEvent, which has the following
84-
attributes
85+
events. The :class:`~matplotlib.backend_bases.KeyEvent` and
86+
:class:`~matplotlib.backend_bases.MouseEvent` classes that handle
87+
these events are both derived from the LocationEvent, which has the
88+
following attributes
8589

8690
======================= ========================================
8791
LocationEvent attribute Description
8892
======================= ========================================
89-
x x position - pixels from left of canvas
90-
y y position - pixels from right of canvas
91-
button button pressed None, 1, 2, 3
92-
inaxes the Axes instance if mouse us over axes
93-
xdata x coord of mouse in data coords
94-
ydata y coord of mouse in data coords
93+
``x`` x position - pixels from left of canvas
94+
``y`` y position - pixels from right of canvas
95+
``button`` button pressed None, 1, 2, 3
96+
``inaxes`` the Axes instance if mouse us over axes
97+
``xdata`` x coord of mouse in data coords
98+
``ydata`` y coord of mouse in data coords
9599
======================= ========================================
96100

97101
Let's look a simple example of a canvas, where a simple line segment
@@ -120,31 +124,33 @@ is created every time a mouse is pressed::
120124

121125

122126

123-
The MouseEvent that we just used is a LocationEvent, so we have access
124-
to the data and pixel coordinates in event.x and event.xdata. In
125-
addition to the LocationEvent attributes, it has
127+
The :class:`~matplotlib.backend_bases.MouseEvent` that we just used is a
128+
:class:`~matplotlib.backend_bases.LocationEvent`, so we have access to
129+
the data and pixel coordinates in event.x and event.xdata. In
130+
addition to the ``LocationEvent`` attributes, it has
126131

127132
==================== ==============================================================
128133
MouseEvent attribute Description
129134
==================== ==============================================================
130-
button button pressed None, 1, 2, 3
131-
key the key pressed: None, chr(range(255)), shift, win, or control
135+
``button`` button pressed None, 1, 2, 3
136+
``key`` the key pressed: None, chr(range(255)), shift, win, or control
132137
==================== ==============================================================
133138

134139
Draggable Rectangle Exercise
135140
----------------------------
136141

137-
Write draggable rectangle class that is initialized with a Rectangle
138-
instance but will move its x,y location when dragged. Hint: you will
139-
need to store the orginal xy location of the rectangle which is stored
140-
as rect.xy and connect to the press, motion and release mouse events.
141-
When the mouse is pressed, check to see if the click occurs over your
142-
rectangle (see rect.contains) and if it does, store the rectangle xy
143-
and the location of the mouse click in data coords. In the motion
144-
event callback, compute the deltax and deltay of the mouse movement,
145-
and add those deltas to the origin of the rectangle you stored. The
146-
redraw the figure. On the button release event, just reset all the
147-
button press data you stored as None.
142+
Write draggable rectangle class that is initialized with a
143+
:class:`~matplotlib.patches.Rectangle` instance but will move its x,y
144+
location when dragged. Hint: you will need to store the orginal
145+
``xy`` location of the rectangle which is stored as rect.xy and
146+
connect to the press, motion and release mouse events. When the mouse
147+
is pressed, check to see if the click occurs over your rectangle (see
148+
:meth:`matplotlib.patches.Rectangle.contains`) and if it does, store
149+
the rectangle xy and the location of the mouse click in data coords.
150+
In the motion event callback, compute the deltax and deltay of the
151+
mouse movement, and add those deltas to the origin of the rectangle
152+
you stored. The redraw the figure. On the button release event, just
153+
reset all the button press data you stored as None.
148154

149155
Here is the solution::
150156

@@ -212,8 +218,9 @@ Here is the solution::
212218
plt.show()
213219

214220

215-
**Extra credit**: use the animation blit techniques discussed at
216-
http://www.scipy.org/Cookbook/Matplotlib/Animations to make the
221+
**Extra credit**: use the animation blit techniques discussed in the
222+
`animations recipe
223+
<http://www.scipy.org/Cookbook/Matplotlib/Animations>`_ to make the
217224
animated drawing faster and smoother.
218225

219226
Extra credit solution::
@@ -325,30 +332,32 @@ Extra credit solution::
325332
Object Picking
326333
==============
327334

328-
You can enable picking by setting the ``picker`` property of an Artist
329-
(eg a matplotlib Line2D, Text, Patch, Polygon, AxesImage,
330-
etc...)
335+
You can enable picking by setting the ``picker`` property of an
336+
:class:`~matplotlib.artist.Artist` (eg a matplotlib
337+
:class:`~matplotlib.lines.Line2D`, :class:`~matplotlib.text.Text`,
338+
:class:`~matplotlib.patches.Patch`, :class:`~matplotlib.patches.Polygon`,
339+
:class:`~matplotlib.patches.AxesImage`, etc...)
331340

332-
There are a variety of meanings of the picker property:
341+
There are a variety of meanings of the ``picker`` property:
333342

334-
- None : picking is disabled for this artist (default)
343+
- ``None`` : picking is disabled for this artist (default)
335344

336-
- boolean : if True then picking will be enabled and the artist will
345+
- ``boolean`` : if True then picking will be enabled and the artist will
337346
fire a pick event if the mouse event is over the artist
338347

339-
- float : if picker is a number it is interpreted as an epsilon
348+
- ``float`` : if picker is a number it is interpreted as an epsilon
340349
tolerance in points and the the artist will fire off an event if its
341350
data is within epsilon of the mouse event. For some artists like
342351
lines and patch collections, the artist may provide additional data
343352
to the pick event that is generated, eg the indices of the data
344353
within epsilon of the pick event.
345354

346-
- function : if picker is callable, it is a user supplied function
355+
- ``function`` : if picker is callable, it is a user supplied function
347356
which determines whether the artist is hit by the mouse event. The
348357
signature is ``hit, props = picker(artist, mouseevent)`` to
349358
determine the hit test. If the mouse event is over the artist,
350-
return hit=True and props is a dictionary of properties you want
351-
added to the PickEvent attributes
359+
return ``hit=True`` and props is a dictionary of properties you want
360+
added to the :class:`~matplotlib.backend_bases.PickEvent` attributes
352361

353362

354363
After you have enabled an artist for picking by setting the ``picker``
@@ -361,22 +370,24 @@ pick callbacks on mouse press events. Eg::
361370
# now do something with this...
362371

363372

364-
The pick event (matplotlib.backend_bases.PickEvent) which is passed to
373+
The :class:`~matplotlib.backend_bases.PickEvent` which is passed to
365374
your callback is always fired with two attributes:
366375

367-
- mouseevent : the mouse event that generate the pick event. The
368-
mouse event in turn has attributes like x and y (the coords in
376+
- ``mouseevent`` : the mouse event that generate the pick event. The
377+
mouse event in turn has attributes like ``x`` and ``y`` (the coords in
369378
display space, eg pixels from left, bottom) and xdata, ydata (the
370379
coords in data space). Additionally, you can get information about
371380
which buttons were pressed, which keys were pressed, which Axes the
372-
mouse is over, etc. See matplotlib.backend_bases.MouseEvent for
381+
mouse is over, etc. See :class:`matplotlib.backend_bases.MouseEvent` for
373382
details.
374383

375-
- artist : the matplotlib.artist that generated the pick event.
384+
- ``artist`` : the :class:`matplotlib.artist.Artist` that generated
385+
the pick event.
376386

377-
Additionally, certain artists like Line2D and PatchCollection may
378-
attach additional meta data like the indices into the data that meet
379-
the picker criteria (eg all the points in the line that are within the
387+
Additionally, certain artists like :class:`~matplotlib.lines.Line2D`
388+
and :class:`~matplotlib.collections.PatchCollection` may attach
389+
additional meta data like the indices into the data that meet the
390+
picker criteria (eg all the points in the line that are within the
380391
specified epsilon tolerance)
381392

382393
Simple picking example
@@ -389,10 +400,10 @@ tolerance distance from the line, and has the indices of the data
389400
vertices that are within the pick distance tolerance. Our onpick
390401
callback function simply prints the data that are under the pick
391402
location. Different matplotlib Artists can attach different data to
392-
the PickEvent. For example, Line2D attaches the ind property, which
393-
are the indices into the line data under the pick point. See
394-
Line2D.pick for details on the PickEvent properties of the line. Here
395-
is the code::
403+
the PickEvent. For example, ``Line2D`` attaches the ind property,
404+
which are the indices into the line data under the pick point. See
405+
:meth:`~matplotlib.lines.Line2D.pick` for details on the ``PickEvent``
406+
properties of the line. Here is the code::
396407

397408
import numpy as np
398409
import matplotlib.pyplot as plt

doc/users/figures/text_commands.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@
1010

1111
ax.set_xlabel('xlabel')
1212
ax.set_ylabel('ylabel')
13-
ax.text(5, 8, 'italics text in data coords', style='italic')
13+
14+
ax.text(5, 8, 'boxed italics text in data coords', style='italic',
15+
bbox={'facecolor':'red', 'alpha':0.5, 'pad':10})
16+
1417
ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=20)
1518

16-
ax.text(0.95, 0.01, 'text in axes coords',
19+
ax.text(4, 3, unicode('unicode: Institut f\374r Festk\366rperphysik', 'latin-1'))
20+
21+
ax.text(0.95, 0.01, 'colored text in axes coords',
1722
verticalalignment='bottom', horizontalalignment='right',
1823
transform=ax.transAxes,
1924
color='green', fontsize=20)

0 commit comments

Comments
 (0)