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

Skip to content

Commit 6d13100

Browse files
committed
fixed some obj picker and cords demo code
svn path=/trunk/matplotlib/; revision=307
1 parent 74c16c3 commit 6d13100

8 files changed

Lines changed: 83 additions & 23 deletions

File tree

API_CHANGES

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ API CHANGES in matplotlib-0.54
33
matlab interface
44
================
55

6+
dpi
7+
---
8+
9+
Several of the backends used a PIXELS_PER_INCH hack that I added to
10+
try and make images render consistently across backends. This just
11+
complicated matters. So you may find that some font sizes and line
12+
widths appear different than before. Apologies for the
13+
inconvenience. You should set the dpi to an accurate value for your
14+
screen to get true sizes.
15+
16+
617
pcolor and scatter
718
------------------
819

@@ -96,12 +107,12 @@ Bounding boxes
96107
get the width and height of the bbox
97108

98109
OLD
99-
width = self.figure.bbox.x.interval()
100-
height = self.figure.bbox.y.interval()
110+
width = fig.bbox.x.interval()
111+
height = fig.bbox.y.interval()
101112

102113
New
103-
width = self.figure.bbox.width()
104-
height = self.figure.bbox.height()
114+
width = fig.bbox.width()
115+
height = fig.bbox.height()
105116

106117

107118

@@ -170,10 +181,23 @@ Transformations
170181
Although this was done in numerix, it still involves 6 length(x)
171182
for-loops (the multiply, add, and function evaluation each for x
172183
and y). Now all of that is done in a single pass.
184+
185+
186+
If you are using transformations and bounding boxes to get the
187+
cursor position in data coordinates, the method calls are a little
188+
different now. See the updated examples/coords_demo.py which shows
189+
you how to do this.
190+
191+
Likewise, if you are using the artist bounding boxes to pick items
192+
on the canvas with the GUI, the bbox methods are somewhat
193+
different. You will need to see the updated
194+
examples/object_picker.py.
173195

174196
See unit/transforms_unit.py for many examples using the new
175197
transformations.
176198

199+
200+
177201
API changes at 0.50
178202

179203
* refactored Figure class so it is no longer backend dependent.

DEVNOTES

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ http://matplotlib.sourceforge.net
2828

2929
0) Turn off all the build flags
3030

31-
0) Run examples/batch_figs.py w/o errors; run the backend specific
32-
demos (object_picker, anim , embedding*)
31+
0) Run examples/backend_driver.py w/o errors; run the backend specific
32+
demos (object_picker, anim , embedding*). Do an explicity numarray
33+
and python2.2 test.
3334

3435
0) Remove MANIFEST so it will be rebuilt by MANIFEST.in
3536

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ examples/multiple_figs_demo.py
232232
examples/object_picker.py
233233
examples/pcolor_demo.py
234234
examples/pcolor_demo2.py
235+
examples/pcolor_small.py
235236
examples/psd_demo.py
236237
examples/pstest.py
237238
examples/pythonic_matplotlib.py

TODO

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366

367367
-- DONE clipping for collections
368368

369-
-- Todd's nx stuff
369+
-- DONE Todd's nx stuff
370370

371371
-- fix object picker and eeg demo
372372

@@ -378,4 +378,7 @@
378378

379379
-- DONE - pcolor edge color
380380

381-
-- convert rank 1 arrays as per Flaviu's post
381+
-- convert rank 1 arrays as per Flaviu's post
382+
383+
-- email tim log bar code after release
384+

examples/coords_demo.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,28 @@
1414

1515
def on_move(widget, event):
1616
# get the x and y coords, flip y from top to bottom
17-
height = canvas.figure.bbox.y.interval()
17+
height = canvas.figure.bbox.height()
1818
x, y = event.x, height-event.y
1919

2020
if ax.in_axes(x, y):
2121
# transData transforms data coords to display coords. Use the
2222
# inverse method to transform back
23-
t = ax.xaxis.transData.inverse_positions(x)
24-
val = ax.yaxis.transData.inverse_positions(y)
25-
print t, val
23+
print ax.transData.inverse_xy_tup( (x,y) )
2624

2725
def on_click(widget, event):
2826
# get the x and y coords, flip y from top to bottom
29-
height = canvas.figure.bbox.y.interval()
27+
height = canvas.figure.bbox.height()
3028
x, y = event.x, height-event.y
3129
if event.button==1:
3230
if ax.in_axes(x, y):
3331
# transData transforms data coords to display coords. Use the
3432
# inverse method to transform back
35-
t = ax.xaxis.transData.inverse_positions(x)
36-
val = ax.yaxis.transData.inverse_positions(y)
37-
38-
print t, val
33+
print ax.transData.inverse_xy_tup( (x,y) )
3934

4035

41-
#canvas.connect('motion_notify_event', on_move)
42-
canvas.connect('button_press_event', on_click)
36+
37+
canvas.connect('motion_notify_event', on_move)
38+
#canvas.connect('button_press_event', on_click)
4339

4440

4541

examples/object_picker.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from matplotlib.lines import Line2D, lineStyles, lineMarkers
2222
from matplotlib.transforms import Bbox, lbwh_to_bbox
2323
from matplotlib.patches import draw_bbox
24+
from matplotlib.cbook import is_string_like
2425
from matplotlib.colors import colorConverter
2526
import gtk
2627

@@ -67,6 +68,7 @@ def make_option_menu( names, func=None ):
6768
menu.show()
6869
d = {}
6970
for label in names:
71+
if not is_string_like(label): continue
7072
item = gtk.MenuItem(label)
7173
menu.append(item)
7274
item.show()
@@ -234,7 +236,7 @@ def pick(self, x, y, epsilon=5):
234236

235237
def over_text(t):
236238
bbox = t.get_window_extent(self.renderer)
237-
return clickBBox.overlap(bbox)
239+
return clickBBox.overlaps(bbox)
238240

239241
def over_line(line):
240242
# can't use the line bbox because it covers the entire extent

src/_transforms.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ Bbox::get_bounds(const Py::Tuple & args) {
188188
return ret;
189189
}
190190

191+
Py::Object
192+
Bbox::contains(const Py::Tuple &args) {
193+
args.verify_length(2);
194+
195+
double x = Py::Float(args[0]);
196+
double y = Py::Float(args[1]);
197+
198+
Interval *ix = intervalx_api();
199+
Interval *iy = intervaly_api();
200+
int b = ix->contains_api(x) && iy->contains_api(y);
201+
delete ix;
202+
delete iy;
203+
return Py::Int(b);
204+
}
205+
191206
Py::Object
192207
Bbox::overlaps(const Py::Tuple &args) {
193208
args.verify_length(1);
@@ -1066,6 +1081,7 @@ void Bbox::init_type()
10661081

10671082
add_varargs_method("ll", &Bbox::ll, "ll()\n");
10681083
add_varargs_method("ur", &Bbox::ur, "ur()\n");
1084+
add_varargs_method("contains" , &Bbox::contains, "contains(x,y)\n");
10691085
add_varargs_method("overlaps" , &Bbox::overlaps, "overlaps(bbox)\n");
10701086
add_varargs_method("overlapsx" , &Bbox::overlapsx, "overlapsx(bbox)\n");
10711087
add_varargs_method("overlapsy" , &Bbox::overlapsy, "overlapsy(bbox)\n");

src/_transforms.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,23 @@ class Point: public Py::PythonExtension<Point> {
138138
class Interval: public Py::PythonExtension<Interval> {
139139
public:
140140
Interval(LazyValue* val1, LazyValue* val2) : _val1(val1), _val2(val2) {};
141+
141142
static void init_type(void);
142143

143144
Py::Object contains( const Py::Tuple &args) {
144145
args.verify_length(1);
145146
double x = Py::Float(args[0]);
147+
int b = contains_api( x);
148+
return Py::Int(b);
149+
}
150+
151+
int contains_api( const double& val) {
152+
146153
double val1 = _val1->val();
147154
double val2 = _val2->val();
148155

149-
int b = ( (x>=val1) && (x<=val2) || (x>=val2) && (x<=val1) );
150-
return Py::Int(b);
156+
return ( (val>=val1) && (val<=val2) || (val>=val2) && (val<=val1) );
157+
151158
}
152159

153160
//update the interval to contain all points in seq of floats
@@ -241,8 +248,18 @@ class Bbox: public Py::PythonExtension<Bbox> {
241248
Py::Object intervaly(const Py::Tuple &args) {
242249
return Py::Object( new Interval( _ll->y_api(), _ur->y_api()));
243250
}
251+
252+
Interval* intervalx_api() {
253+
return new Interval( _ll->x_api(), _ur->x_api());
254+
}
255+
256+
Interval* intervaly_api() {
257+
return new Interval( _ll->y_api(), _ur->y_api());
258+
}
259+
244260
// update the current bbox with data from xy tuples
245261
Py::Object update(const Py::Tuple &args);
262+
Py::Object contains(const Py::Tuple &args);
246263

247264
Py::Object width(const Py::Tuple &args) {
248265
double w = _ur->xval() - _ll->xval();
@@ -335,7 +352,7 @@ class Log : public Func {
335352

336353
//the inverse mapping
337354
double inverse_api(const double& x) {
338-
return pow10(x);
355+
return pow(x,10.0);
339356
};
340357
};
341358

0 commit comments

Comments
 (0)