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

Skip to content

Commit 1ec2767

Browse files
committed
fixed images to fit in subplots
svn path=/trunk/matplotlib/; revision=178
1 parent d0f4115 commit 1ec2767

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

TODO

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,6 @@
268268

269269
-- DONE add figure legend
270270

271-
-- fix newlines across backends
271+
-- fix newlines across backends
272+
273+
-- support partial window expose redraws in agg

examples/image_demo.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22
from matplotlib.image import NEAREST, BILINEAR, BICUBIC, SPLINE16
33
from matplotlib.matlab import *
44

5-
5+
w, h = 512, 512
66
s = file('data/ct.raw', 'rb').read()
77
A = fromstring(s, typecode=UInt16).astype(Float)
88
A *= 1.0/max(A)
9-
A.shape = 512, 512
9+
A.shape = w, h
10+
1011

12+
figure(1, figsize=(2,7))
13+
subplot(211)
1114
im = imshow(A)
1215
#im.set_interpolation(BICUBIC)
1316
#im.set_interpolation(NEAREST)
1417
im.set_interpolation(BILINEAR)
1518
#im.set_preserve_aspect(ASPECT_PRESERVE)
19+
set(gca(), 'xlim', [0,h-1])
20+
axis('off')
21+
title('CT density')
1622

17-
18-
23+
x = sum(A,0)
24+
subplot(212)
25+
bar(arange(w), x)
26+
set(gca(), 'xlim', [0,h-1])
27+
ylabel('density')
28+
set(gca(), 'xticklabels', [])
1929
show()
2030

src/_backend_agg.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <png.h>
33
#include "ft2font.h"
44
#include "_backend_agg.h"
5-
#include "_image.h"
5+
#include "image.h"
66

77
static PyObject *ErrorObject;
88

@@ -572,12 +572,14 @@ PyObject *
572572
RendererAgg_draw_image(RendererAggObject *renderer, PyObject* args) {
573573

574574
ImageObject *image;
575-
long x, y;
575+
int x, y;
576576
if (!PyArg_ParseTuple(args, "iiO", &x, &y, &image))
577577
return NULL;
578578

579579
//todo: handle x and y
580-
renderer->rbuf->copy_from(*image->rbufOut);
580+
agg::rect r(0, 0, image->widthOut, image->heightOut);
581+
582+
renderer->rbase->copy_from(*image->rbufOut, &r, x, y);
581583
Py_INCREF(Py_None);
582584
return Py_None;
583585

src/_backend_agg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
*
33
* $Header$
44
* $Log$
5+
* Revision 1.5 2004/03/12 23:25:09 jdh2358
6+
* fixed images to fit in subplots
7+
*
58
* Revision 1.4 2004/03/03 19:27:43 jdh2358
69
* fixed gtk vert text bug
710
*
@@ -24,6 +27,7 @@
2427
#include <cstdio>
2528

2629
#include "agg_arrowhead.h"
30+
#include "agg_basics.h"
2731
#include "agg_conv_concat.h"
2832
#include "agg_conv_contour.h"
2933
#include "agg_conv_curve.h"

0 commit comments

Comments
 (0)