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

Skip to content

Commit fd3db7f

Browse files
committed
Fixed bug in updating dataLim when an axis is reversed
svn path=/trunk/matplotlib/; revision=3904
1 parent c377de3 commit fd3db7f

2 files changed

Lines changed: 116 additions & 17 deletions

File tree

CHANGELOG

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
2007-09-30 Modified update* methods of Bbox and Interval so they
2+
work with reversed axes. Prior to this, trying to
3+
set the ticks on a reversed axis failed with an
4+
uninformative error message. - EF
5+
6+
2007-09-30 Applied patches to axes3d to fix index error problem - EF
7+
18
2007-09-24 Applied Eike Welk's patch reported on mpl-dev on 2007-09-22
29
Fixes a bug with multiple plot windows in the qt backend,
310
ported the changes to backend_qt4 as well - DSD
411

5-
2007-09-21 Changed cbook.reversed to yield the same result as the
12+
2007-09-21 Changed cbook.reversed to yield the same result as the
613
python reversed builtin - DSD
714

815
2007-09-13 The usetex support in the pdf backend is more usable now,

src/_transforms.cpp

Lines changed: 108 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,19 @@ Interval::update(const Py::Tuple &args) {
159159

160160
double minx = _val1->val();
161161
double maxx = _val2->val();
162+
int reversed = 0;
163+
if (minx > maxx) {
164+
reversed = 1;
165+
double tmp = minx;
166+
minx = maxx;
167+
maxx = tmp;
168+
}
162169

163170

164171

165172
double thisval;
166173
thisval = Py::Float(vals[0]);
167-
if (ignore) {
174+
if (ignore) {
168175
minx = thisval;
169176
maxx = thisval;
170177
}
@@ -176,9 +183,13 @@ Interval::update(const Py::Tuple &args) {
176183
_minpos->update(thisval);
177184
}
178185

179-
180-
_val1->set_api(minx);
181-
_val2->set_api(maxx);
186+
if (reversed) {
187+
_val1->set_api(maxx);
188+
_val2->set_api(minx);
189+
} else {
190+
_val1->set_api(minx);
191+
_val2->set_api(maxx);
192+
}
182193
return Py::Object();
183194
}
184195

@@ -459,8 +470,24 @@ Bbox::update(const Py::Tuple &args) {
459470

460471
double minx = _ll->xval();
461472
double maxx = _ur->xval();
473+
int xreversed = 0;
474+
if (minx > maxx) {
475+
xreversed = 1;
476+
double tmp = minx;
477+
minx = maxx;
478+
maxx = tmp;
479+
}
480+
481+
462482
double miny = _ll->yval();
463483
double maxy = _ur->yval();
484+
int yreversed = 0;
485+
if (miny > maxy) {
486+
yreversed = 1;
487+
double tmp = miny;
488+
miny = maxy;
489+
maxy = tmp;
490+
}
464491

465492
Py::Tuple tup;
466493
if (ignore) {
@@ -482,11 +509,22 @@ Bbox::update(const Py::Tuple &args) {
482509
if (y>maxy) maxy=y;
483510
}
484511

512+
if (xreversed) {
513+
_ll->x_api()->set_api(maxx);
514+
_ur->x_api()->set_api(minx);
515+
} else {
516+
_ll->x_api()->set_api(minx);
517+
_ur->x_api()->set_api(maxx);
518+
}
519+
520+
if (yreversed) {
521+
_ll->y_api()->set_api(maxy);
522+
_ur->y_api()->set_api(miny);
523+
} else {
524+
_ll->y_api()->set_api(miny);
525+
_ur->y_api()->set_api(maxy);
526+
}
485527

486-
_ll->x_api()->set_api(minx);
487-
_ll->y_api()->set_api(miny);
488-
_ur->x_api()->set_api(maxx);
489-
_ur->y_api()->set_api(maxy);
490528
return Py::Object();
491529
}
492530

@@ -519,8 +557,24 @@ Bbox::update_numerix_xy(const Py::Tuple &args) {
519557

520558
double minx = _ll->xval();
521559
double maxx = _ur->xval();
560+
int xreversed = 0;
561+
if (minx > maxx) {
562+
xreversed = 1;
563+
double tmp = minx;
564+
minx = maxx;
565+
maxx = tmp;
566+
}
567+
568+
522569
double miny = _ll->yval();
523570
double maxy = _ur->yval();
571+
int yreversed = 0;
572+
if (miny > maxy) {
573+
yreversed = 1;
574+
double tmp = miny;
575+
miny = maxy;
576+
maxy = tmp;
577+
}
524578

525579
double thisx, thisy;
526580
//don't use current bounds on first update
@@ -550,10 +604,21 @@ Bbox::update_numerix_xy(const Py::Tuple &args) {
550604

551605
Py_XDECREF(xyin);
552606
if (ngood) {
553-
_ll->x_api()->set_api(minx);
554-
_ll->y_api()->set_api(miny);
555-
_ur->x_api()->set_api(maxx);
556-
_ur->y_api()->set_api(maxy);
607+
if (xreversed) {
608+
_ll->x_api()->set_api(maxx);
609+
_ur->x_api()->set_api(minx);
610+
} else {
611+
_ll->x_api()->set_api(minx);
612+
_ur->x_api()->set_api(maxx);
613+
}
614+
615+
if (yreversed) {
616+
_ll->y_api()->set_api(maxy);
617+
_ur->y_api()->set_api(miny);
618+
} else {
619+
_ll->y_api()->set_api(miny);
620+
_ur->y_api()->set_api(maxy);
621+
}
557622
}
558623
return Py::Object();
559624
}
@@ -594,8 +659,24 @@ Bbox::update_numerix(const Py::Tuple &args) {
594659

595660
double minx = _ll->xval();
596661
double maxx = _ur->xval();
662+
int xreversed = 0;
663+
if (minx > maxx) {
664+
xreversed = 1;
665+
double tmp = minx;
666+
minx = maxx;
667+
maxx = tmp;
668+
}
669+
670+
597671
double miny = _ll->yval();
598672
double maxy = _ur->yval();
673+
int yreversed = 0;
674+
if (miny > maxy) {
675+
yreversed = 1;
676+
double tmp = miny;
677+
miny = maxy;
678+
maxy = tmp;
679+
}
599680

600681
double thisx, thisy;
601682
//don't use current bounds on first update
@@ -627,10 +708,21 @@ Bbox::update_numerix(const Py::Tuple &args) {
627708
Py_XDECREF(y);
628709

629710

630-
_ll->x_api()->set_api(minx);
631-
_ll->y_api()->set_api(miny);
632-
_ur->x_api()->set_api(maxx);
633-
_ur->y_api()->set_api(maxy);
711+
if (xreversed) {
712+
_ll->x_api()->set_api(maxx);
713+
_ur->x_api()->set_api(minx);
714+
} else {
715+
_ll->x_api()->set_api(minx);
716+
_ur->x_api()->set_api(maxx);
717+
}
718+
719+
if (yreversed) {
720+
_ll->y_api()->set_api(maxy);
721+
_ur->y_api()->set_api(miny);
722+
} else {
723+
_ll->y_api()->set_api(miny);
724+
_ur->y_api()->set_api(maxy);
725+
}
634726
return Py::Object();
635727
}
636728

0 commit comments

Comments
 (0)