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

Skip to content

Commit 47e1c66

Browse files
committed
added origin support for composite images
svn path=/trunk/matplotlib/; revision=5618
1 parent b8fc240 commit 47e1c66

7 files changed

Lines changed: 25 additions & 6 deletions

File tree

examples/api/mathtext_asarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
parser = mathtext.MathTextParser("Bitmap")
1212

13+
1314
parser.to_png('test2.png', r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} y\right)\right]$', color='green', fontsize=14, dpi=100)
1415

1516

@@ -20,5 +21,4 @@
2021
fig.figimage(rgba1.astype(float)/255., 100, 100)
2122
fig.figimage(rgba2.astype(float)/255., 100, 300)
2223

23-
2424
plt.show()

examples/pylab_examples/figimage_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
im1 = figimage(Z, xo=50, yo=0)
1414
im2 = figimage(Z, xo=100, yo=100, alpha=.8)
1515
#gray() # overrides current and sets default
16-
savefig('figimage_demo')
16+
#savefig('figimage_demo')
1717

1818
show()
1919

2020

21+

lib/matplotlib/axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,9 @@ def draw(self, renderer=None, inframe=False):
14421442
im = mimage.from_images(height,
14431443
width,
14441444
ims)
1445+
if self.images[0].origin=='upper':
1446+
im.flipud_out()
1447+
14451448
im.is_grayscale = False
14461449
l, b, w, h = self.bbox.bounds
14471450
# composite images need special args so they will not

lib/matplotlib/backends/backend_gtkagg.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def new_figure_manager(num, *args, **kwargs):
4747
class FigureCanvasGTKAgg(FigureCanvasGTK, FigureCanvasAgg):
4848
filetypes = FigureCanvasGTK.filetypes.copy()
4949
filetypes.update(FigureCanvasAgg.filetypes)
50-
50+
5151
def configure_event(self, widget, event=None):
5252

5353
if DEBUG: print 'FigureCanvasGTKAgg.configure_event'
@@ -80,6 +80,14 @@ def _render_figure(self, pixmap, width, height):
8080
ren = self.get_renderer()
8181
w = int(ren.width)
8282
h = int(ren.height)
83+
84+
# There apparently is a bug here on some versions of pygtk
85+
# (2.6) that crops up in corner cases. Eg, in
86+
# figimage_demo.py, there is background pixel noise because
87+
# the figure frame is off and the blended image background has
88+
# alpha 0. and you see the uninitialzed data ("screen noise").
89+
# If in _image.cpp Image:from_image you fill the background
90+
# with a non transparent value, it goes away.
8391
pixbuf = gtk.gdk.pixbuf_new_from_data(
8492
buf, gtk.gdk.COLORSPACE_RGB, True, 8, w, h, w*4)
8593
pixmap.draw_pixbuf(pixmap.new_gc(), pixbuf, 0, 0, 0, 0, w, h,

lib/matplotlib/figure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ def draw(self, renderer):
807807
im = _image.from_images(self.bbox.height * mag,
808808
self.bbox.width * mag,
809809
ims)
810+
if self.images[0].origin=='upper':
811+
im.flipud_out()
812+
810813
im.is_grayscale = False
811814
l, b, w, h = self.bbox.bounds
812815
clippath, affine = self.get_transformed_clip_path_and_affine()

src/_gtkagg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class _gtkagg_module : public Py::ExtensionModule<_gtkagg_module>
9494
destrbuf.attach(destbuffer, destwidth, destheight, deststride);
9595
pixfmt destpf(destrbuf);
9696
renderer_base destrb(destpf);
97-
//destrb.clear(agg::rgba(1, 0, 0));
97+
98+
//destrb.clear(agg::rgba(1, 1, 1, 0));
9899

99100
agg::rect_base<int> region(destx, desty, (int)r, srcheight-(int)b);
100101
destrb.copy_from(*aggRenderer->renderingBuffer, &region,

src/_image.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,11 +739,14 @@ _image_module::from_images(const Py::Tuple& args) {
739739
renderer_base rb(pixf);
740740

741741

742+
//clear the background of the rendering buffer with alpha 1 and the
743+
//gtkagg screen noise problem in figimage_demo.py goes away -- see
744+
//comment backend_gtkagg.py _render_figure method JDH
745+
//rb.clear(agg::rgba(1, 1, 1, 1));
746+
742747
for (size_t imnum=0; imnum< N; imnum++) {
743748
tup = Py::Tuple(tups[imnum]);
744749
Image* thisim = static_cast<Image*>(tup[0].ptr());
745-
if (imnum==0)
746-
rb.clear(thisim->bg);
747750
ox = Py::Int(tup[1]);
748751
oy = Py::Int(tup[2]);
749752

0 commit comments

Comments
 (0)