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

Skip to content

Commit e264c45

Browse files
committed
fixed a subplot delaxes bug with hspace=0
svn path=/trunk/matplotlib/; revision=2856
1 parent 3939a5d commit e264c45

4 files changed

Lines changed: 48 additions & 16 deletions

File tree

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2006-11-02 Fixed a pylab subplot bug that was causing axes to be
2+
deleted with hspace or wspace equals zero in
3+
subplots_adjust - JDH
4+
15
2006-10-31 Applied axes3d patch 1587359
26
http://sourceforge.net/tracker/index.php?func=detail&aid=1587359&group_id=80706&atid=560722
37
JDH

lib/matplotlib/pylab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ def subplot(*args, **kwargs):
10201020
byebye = []
10211021
for other in fig.axes:
10221022
if other==a: continue
1023-
if bbox.overlaps(other.bbox):
1023+
if bbox.overlaps(other.bbox, ignoreend=True):
10241024
byebye.append(other)
10251025
for ax in byebye: delaxes(ax)
10261026

src/_transforms.cpp

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,15 +322,17 @@ Bbox::contains(const Py::Tuple &args) {
322322
}
323323

324324
Py::Object
325-
Bbox::overlaps(const Py::Tuple &args) {
325+
Bbox::overlaps(const Py::Tuple &args, const Py::Dict &kwargs) {
326326
_VERBOSE("Bbox::overlaps");
327327
args.verify_length(1);
328328

329329
if (! check(args[0]))
330330
throw Py::TypeError("Expected a bbox");
331331

332-
int x = Py::Int( overlapsx(args) );
333-
int y = Py::Int( overlapsy(args) );
332+
333+
334+
int x = Py::Int( overlapsx(args, kwargs) );
335+
int y = Py::Int( overlapsy(args, kwargs) );
334336
return Py::Int(x&&y);
335337
}
336338

@@ -343,13 +345,18 @@ Bbox::ignore(const Py::Tuple &args) {
343345
}
344346

345347
Py::Object
346-
Bbox::overlapsx(const Py::Tuple &args) {
348+
Bbox::overlapsx(const Py::Tuple &args, const Py::Dict &kwargs) {
347349
_VERBOSE("Bbox::overlapsx");
348350
args.verify_length(1);
349351

350352
if (! check(args[0]))
351353
throw Py::TypeError("Expected a bbox");
352354

355+
int ignoreend = false;
356+
if (kwargs.hasKey("ignoreend")) {
357+
ignoreend = Py::Int(kwargs["ignoreend"]);
358+
}
359+
353360
Bbox* other = static_cast<Bbox*>(args[0].ptr());
354361

355362
double minx = _ll->xval();
@@ -358,20 +365,34 @@ Bbox::overlapsx(const Py::Tuple &args) {
358365
double ominx = other->_ll->xval();
359366
double omaxx = other->_ur->xval();
360367

361-
int b = ( ( (ominx>=minx) && (ominx<=maxx)) ||
362-
( (minx>=ominx) && (minx<=omaxx)) );
368+
int b=0;
369+
if (ignoreend) {
370+
b = ( ( (ominx>minx) && (ominx<maxx)) ||
371+
( (minx>ominx) && (minx<omaxx)) );
372+
}
373+
else{
374+
b = ( ( (ominx>=minx) && (ominx<=maxx)) ||
375+
( (minx>=ominx) && (minx<=omaxx)) );
376+
377+
}
363378
return Py::Int(b);
364379

365380
}
366381

367382
Py::Object
368-
Bbox::overlapsy(const Py::Tuple &args) {
383+
Bbox::overlapsy(const Py::Tuple &args, const Py::Dict &kwargs) {
369384
_VERBOSE("Bbox::overlapsy");
370385
args.verify_length(1);
371386

372387
if (! check(args[0]))
373388
throw Py::TypeError("Expected a bbox");
374389

390+
391+
int ignoreend = false;
392+
if (kwargs.hasKey("ignoreend")) {
393+
ignoreend = Py::Int(kwargs["ignoreend"]);
394+
}
395+
375396
Bbox* other = static_cast<Bbox*>(args[0].ptr());
376397

377398
double miny = _ll->yval();
@@ -381,9 +402,16 @@ Bbox::overlapsy(const Py::Tuple &args) {
381402
double omaxy = other->_ur->yval();
382403

383404

405+
int b=0;
406+
if (ignoreend) {
407+
b = ( ( (ominy>miny) && (ominy<maxy)) ||
408+
( (miny>ominy) && (miny<omaxy)) );
409+
}
410+
else {
411+
b = ( ( (ominy>=miny) && (ominy<=maxy)) ||
412+
( (miny>=ominy) && (miny<=omaxy)) );
384413

385-
int b = ( ( (ominy>=miny) && (ominy<=maxy)) ||
386-
( (miny>=ominy) && (miny<=omaxy)) );
414+
}
387415
return Py::Int(b);
388416

389417
}
@@ -2203,9 +2231,9 @@ Bbox::init_type()
22032231
add_varargs_method("ur", &Bbox::ur, "ur()\n");
22042232
add_varargs_method("contains" , &Bbox::contains, "contains(x,y)\n");
22052233
add_varargs_method("count_contains", &Bbox::count_contains, "count_contains(xys)\n");
2206-
add_varargs_method("overlaps" , &Bbox::overlaps, "overlaps(bbox)\n");
2207-
add_varargs_method("overlapsx" , &Bbox::overlapsx, "overlapsx(bbox)\n");
2208-
add_varargs_method("overlapsy" , &Bbox::overlapsy, "overlapsy(bbox)\n");
2234+
add_keyword_method("overlaps" , &Bbox::overlaps, "overlaps(bbox)\n");
2235+
add_keyword_method("overlapsx" , &Bbox::overlapsx, "overlapsx(bbox)\n");
2236+
add_keyword_method("overlapsy" , &Bbox::overlapsy, "overlapsy(bbox)\n");
22092237
add_varargs_method("intervalx" , &Bbox::intervalx, "intervalx()\n");
22102238
add_varargs_method("intervaly" , &Bbox::intervaly, "intervaly()\n");
22112239

src/_transforms.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ class Bbox: public Py::PythonExtension<Bbox> {
348348
}
349349

350350
//return true if bboxes overlap
351-
Py::Object overlaps(const Py::Tuple &args);
351+
Py::Object overlaps(const Py::Tuple &args, const Py::Dict &kwargs);
352352
//return true if the x extent overlaps
353-
Py::Object overlapsx(const Py::Tuple &args);
353+
Py::Object overlapsx(const Py::Tuple &args, const Py::Dict &kwargs);
354354
//return true if the x extent overlaps
355-
Py::Object overlapsy(const Py::Tuple &args);
355+
Py::Object overlapsy(const Py::Tuple &args, const Py::Dict &kwargs);
356356

357357
//set the ignore attr
358358
Py::Object ignore(const Py::Tuple &args);

0 commit comments

Comments
 (0)