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

Skip to content

Commit b2b80fe

Browse files
committed
fixed from_images to respect stride
svn path=/trunk/matplotlib/; revision=6381
1 parent cb1f42d commit b2b80fe

5 files changed

Lines changed: 20 additions & 20 deletions

File tree

examples/pylab_examples/figimage_demo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
Z.shape = 100,100
1313
Z[:,50:] = 1.
1414

15-
im1 = plt.figimage(Z, xo=50, yo=0, cmap=cm.jet, origin='upper')
16-
im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, cmap=cm.jet, origin='upper')
15+
im1 = plt.figimage(Z, xo=50, yo=0, cmap=cm.jet, origin='lower')
16+
im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, cmap=cm.jet, origin='lower')
1717

18-
fig.savefig('figimage_demo.png')
19-
fig.savefig('figimage_demo.svg')
20-
fig.savefig('figimage_demo.pdf')
18+
#fig.savefig('figimage_demo.png')
19+
#fig.savefig('figimage_demo.svg')
20+
#fig.savefig('figimage_demo.pdf')
2121
plt.show()
2222

2323

examples/pylab_examples/layer_images.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ def func3(x,y):
2525

2626
xmin, xmax, ymin, ymax = amin(x), amax(x), amin(y), amax(y)
2727
extent = xmin, xmax, ymin, ymax
28+
fig = plt.figure(frameon=False)
29+
2830
Z1 = array(([0,1]*4 + [1,0]*4)*4); Z1.shape = 8,8 # chessboard
2931
im1 = imshow(Z1, cmap=cm.gray, interpolation='nearest',
30-
extent=extent, origin='lower')
32+
extent=extent)
3133
hold(True)
3234

3335
Z2 = func3(X, Y)
3436

3537
im2 = imshow(Z2, cmap=cm.jet, alpha=.9, interpolation='bilinear',
36-
extent=extent, origin='lower')
38+
extent=extent)
3739
#axis([xmin, xmax, ymin, ymax])
3840

3941

lib/matplotlib/axes.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,11 +1536,6 @@ def draw(self, renderer=None, inframe=False):
15361536
ims = [(im.make_image(mag),0,0)
15371537
for im in self.images if im.get_visible()]
15381538

1539-
#flip the images if their origin is "upper"
1540-
for _im, (im,_,_) in zip(self.images, ims):
1541-
if _im.origin=="upper":
1542-
im.flipud_out()
1543-
15441539

15451540
l, b, r, t = self.bbox.extents
15461541
width = mag*((round(r) + 0.5) - (round(l) - 0.5))

lib/matplotlib/figure.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,11 +753,6 @@ def draw(self, renderer):
753753
ims = [(im.make_image(mag), im.ox*mag, im.oy*mag)
754754
for im in self.images]
755755

756-
for _im, (im,_,_) in zip(self.images, ims):
757-
if _im.origin=="upper":
758-
im.flipud_out()
759-
760-
761756
im = _image.from_images(self.bbox.height * mag,
762757
self.bbox.width * mag,
763758
ims)

src/_image.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ Image::flipud_out(const Py::Tuple& args) {
104104

105105
args.verify_length(0);
106106
int stride = rbufOut->stride();
107+
//std::cout << "flip before: " << rbufOut->stride() << std::endl;
107108
rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);
109+
//std::cout << "flip after: " << rbufOut->stride() << std::endl;
108110
return Py::Object();
109111
}
110112

@@ -744,18 +746,24 @@ _image_module::from_images(const Py::Tuple& args) {
744746

745747

746748
rb.clear(agg::rgba(1, 1, 1, 1));
747-
748749
for (size_t imnum=0; imnum< N; imnum++) {
749750
tup = Py::Tuple(tups[imnum]);
750751
Image* thisim = static_cast<Image*>(tup[0].ptr());
751752
ox = Py::Int(tup[1]);
752753
oy = Py::Int(tup[2]);
753-
754+
bool isflip = (thisim->rbufOut->stride())<0;
755+
//std::cout << "from images " << isflip << "; stride=" << thisim->rbufOut->stride() << std::endl;
754756
size_t ind=0;
755757
for (size_t j=0; j<thisim->rowsOut; j++) {
756758
for (size_t i=0; i<thisim->colsOut; i++) {
757759
thisx = i+ox;
758-
thisy = j+oy;
760+
761+
if (isflip)
762+
thisy = thisim->rowsOut - j + oy;
763+
else
764+
thisy = j+oy;
765+
766+
759767
if (thisx>=numcols || thisy>=numrows) {
760768
ind +=4;
761769
continue;

0 commit comments

Comments
 (0)