8000 added table demo example · matplotlib/matplotlib@abaedf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit abaedf1

Browse files
committed
added table demo example
svn path=/trunk/matplotlib/; revision=140
1 parent 6cc5c32 commit abaedf1

File tree

9 files changed

+139
-16
lines changed

9 files changed

+139
-16
lines changed

MANIFEST

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ INSTALL
55
INTERACTIVE
66
KNOWN_BUGS
77
LICENSE
8+
MANIFEST
89
MANIFEST.in
910
Makefile
1011
README
@@ -39,6 +40,7 @@ examples/gdtest.py
3940
examples/histogram_demo.py
4041
examples/interactive.py
4142
examples/interactive2.py
43+
examples/jdh.py
4244
examples/legend_demo.py
4345
examples/legend_demo2.py
4446
examples/line_styles.py
@@ -65,6 +67,7 @@ examples/system_monitor.py
6567
examples/table_demo.py
6668
examples/text_handles.py
6769
examples/text_themes.py
70+
examples/vertical_ticklabels.py
6871
examples/vline_demo.py
6972
examples/wx_demo.py
7073
examples/xvfb_demo.py
@@ -167,6 +170,10 @@ matplotlib/backends/backend_ps.py
167170
matplotlib/backends/backend_template.py
168171
matplotlib/backends/backend_wx.py
169172
matplotlib/backends/ttf_font_manager.py
173+
src/_backend_agg.cpp
174+
src/_backend_agg.h
175+
src/_gtkgd.c
176+
src/font.c
170177
test/README
171178
test/alignment_test.py
172179
test/backend_agg_test.py

MANIFEST.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ include fonts/ttf/*
1111
include images/*
1212
include test/*.py
1313
include test/README
14-
14+
include src/*.cpp
15+
include src/*.c
16+
include src/*.h

TODO

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,9 @@
186186
-- DONE 2004-02-11 explaing the new interactive syntax on
187187
http://matplotlib.sourceforge.net/interactive.html
188188

189+
-- DONE 2004-02-11 lost backend_gtk rotate_text fix - find it!
190+
191+
-- GTK clipping broken?
192+
193+
-- GTK facecolor reversed for line markers
194+

examples/simple_plot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
s = sin(2*2*pi*t)
66
plot(t, s, 'x')
77

8+
89
xlabel('time (s)')
910
ylabel('voltage (mV)')
1011
title('About as simple as it gets, folks')

examples/subplot_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ def f(t):
2222
xlabel('time (s)')
2323
ylabel('Undamped')
2424

25-
savefig('subplot_demo', dpi=600)
25+
savefig('subplot_demo', dpi=300)
2626
show()
2727

examples/table_demo.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import matplotlib
2+
3+
from matplotlib.matlab import *
4+
from colours import get_colours
5+
6+
axes([0.2, 0.2, 0.7, 0.6]) # leave room below the axes for the table
7+
8+
data = [[ 66386, 174296, 75131, 577908, 32015],
9+
[ 58230, 381139, 78045, 99308, 160454],
10+
[ 89135, 80552, 152558, 497981, 603535],
11+
[ 78415, 81858, 150656, 193263, 69638],
12+
[ 139361, 331509, 343164, 781380, 52269]]
13+
14+
colLabels = ('Freeze', 'Wind', 'Flood', 'Quake', 'Hail')
15+
rowLabels = ['%d year' % x for x in (100, 50, 20, 10, 5)]
16+
17+
# Get some pastel shades for the colours
18+
colours = get_colours(len(colLabels))
19+
colours.reverse()
20+
rows = len(data)
21+
22+
ind = arange(len(colLabels)) + 0.3 # the x locations for the groups
23+
cellText = []
24+
width = 0.4 # the width of the bars
25+
yoff = array([0.0] * len(colLabels)) # the bottom values for stacked bar chart
26+
for row in xrange(rows):
27+
bar(ind, data[row], width, bottom=yoff, color=colours[row])
28+
yoff = yoff + data[row]
29+
cellText.append(['%1.1f' % (x/1000.0) for x in yoff])
30+
31+
# Add a table at the bottom of the axes
32+
colours.reverse()
33+
cellText.reverse()
34+
the_table = table(cellText=cellText,
35+
rowLabels=rowLabels, rowColours=colours,
36+
colLabels=colLabels)
37+
ylabel("Loss $1000's")
38+
yticks = arange(0, 2500, 500)
39+
set(gca(), 'yticks', yticks*1000)
40+
set(gca(), 'yticklabels', ['%d' % val for val in yticks])
41+
set(gca(), 'xticks', [])
42+
title('Loss by Disaster')
43+
show()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
ext_modules = []
1414

15-
if 1: # how do I add '--with-gtkgd' flag checking?
15+
if 0: # how do I add '--with-gtkgd' flag checking?
1616
build_gtkgd(ext_modules)
1717

1818
if 1:
1919
build_agg(ext_modules)
2020

2121
setup(name="matplotlib",
22-
version= '0.50j',
22+
version= '0.50k',
2323
description = "Matlab style python plotting package",
2424
author = "John D. Hunter",
2525
author_email="jdhunter@ace.bsd.uchicago.edu",

setupext.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,22 @@ def build_gtkgd(ext_modules):
5151

5252
def add_agg_flags(module):
5353
'Add the module flags to build extensions which use gtk'
54-
include_dirs = ['/usr/X11R6/include', '/home/jdhunter/c/src/agg2/include',
55-
'/usr/include/freetype1', 'src']
54+
include_dirs = [
55+
'src', '/usr/X11R6/include', '/home/jdhunter/c/src/agg2/include',
56+
'/usr/include/freetype1']
5657
library_dirs = ['/usr/X11R6/lib', '/home/jdhunter/c/src/agg2/src']
57-
libraries = ['agg', 'X11', 'm', 'freetype', 'png']
58+
libraries = ['agg', 'X11', 'm', 'ttf', 'png', 'z']
5859
extra_link_args = []
5960
module.include_dirs.extend(include_dirs)
6061
module.libraries.extend(libraries)
6162
module.library_dirs.extend(library_dirs)
6263
module.extra_link_args.extend(extra_link_args)
6364

6465
def build_agg(ext_modules):
65-
module = Extension('matplotlib.backends._backend_agg',
66-
['src/_backend_agg.cpp'],
67-
)
66+
module = Extension(
67+
'matplotlib.backends._backend_agg',
68+
['src/_backend_agg.cpp', 'src/font.cpp'],
69+
)
6870
add_agg_flags(module)
6971
ext_modules.append(module)
7072

src/_backend_agg.cpp

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
#include <cstring>
44

5+
6+
// font stuff from paint
7+
8+
static char agg_font__doc__[] =
9+
"Font(filename, size = 12, rotate = 0)\n"
10+
"\n"
11+
"Load the named font and return the font object";
12+
13+
static PyObject *agg_font(PyObject *module, PyObject *args)
14+
{
15+
return font_new(ar F42D gs);
16+
}
17+
18+
19+
520
// image renderers that also have to deal with points (72/inch) make
621
// an assumption about how many pixels represent 1 inch. GD and paint
722
// use 96. What's good for the goose ...
@@ -279,7 +294,6 @@ _gc_get_linewidth(PyObject *gc) {
279294

280295
extern "C" staticforward PyTypeObject RendererAgg_Type;
281296

282-
283297
#define RendererAggObject_Check(v) ((v)->ob_type == &RendererAgg_Type)
284298

285299
static RendererAggObject *
@@ -597,6 +611,48 @@ RendererAgg_draw_lines(RendererAggObject *renderer, PyObject* args) {
597611
}
598612

599613

614+
615+
static char RendererAgg_rgb__doc__[] =
616+
"rgb(r, g, b)\n"
617+
"\n"
618+
"Create an rgba color value with a = 0xff.";
619+
620+
static PyObject *RendererAgg_rgb(PyObject *self, PyObject *args)
621+
{
622+
int r, g, b;
623+
624+
if (!PyArg_ParseTuple(args, "iii", &r, &g, &b))
625+
return NULL;
626+
627+
return (PyObject*)PyInt_FromLong((r << 24) + (g << 16) + (b << 8) + 0xff);
628+
}
629+
630+
static char RendererAgg_rgba__doc__[] =
631+
"rgba(r, g, b, a)\n"
632+
"\n"
633+
"Create an rgba color value.";
634+
635+
static PyObject *RendererAgg_rgba(PyObject *self, PyObject *args)
636+
{
637+
int r, g, b, a;
638+
639+
if (!PyArg_ParseTuple(args, "iiii", &r, &g, &b, &a))
640+
return NULL;
641+
642+
return (PyObject*)PyInt_FromLong((r << 24) + (g << 16) + (b << 8) + a);
643+
}
644+
645+
char RendererAgg_draw_text__doc__[] =
646+
"draw_text(font, x, y, textcolor, text)\n"
647+
"\n"
648+
"Render the text in the supplied font at the specified location";
649+
650+
PyObject *
651+
RendererAgg_draw_text(RendererAggObject *renderer, PyObject* args) {
652+
653+
return font_draw_text(renderer, args);
654+
}
655+
600656
static PyObject *
601657
RendererAgg_write_rgba(RendererAggObject *renderer, PyObject* args) {
602658
//printf("save buffer called\n");
@@ -702,11 +758,15 @@ RendererAgg_write_png(RendererAggObject *renderer, PyObject *args)
702758
// must be defined before getattr
703759
static PyMethodDef RendererAgg_methods[] = {
704760

705-
{"draw_ellipse", (PyCFunction)RendererAgg_draw_ellipse, METH_VARARGS},
706-
{"draw_rectangle", (PyCFunction)RendererAgg_draw_rectangle, METH_VARARGS},
707-
{"draw_lines", (PyCFunction)RendererAgg_draw_lines, METH_VARARGS},
708-
{"write_rgba", (PyCFunction)RendererAgg_write_rgba, METH_VARARGS},
709-
{"write_png", (PyCFunction)RendererAgg_write_png, METH_VARARGS},
761+
{ "draw_ellipse", (PyCFunction)RendererAgg_draw_ellipse, METH_VARARGS},
762+
{ "draw_rectangle", (PyCFunction)RendererAgg_draw_rectangle, METH_VARARGS},
763+
{ "draw_lines", (PyCFunction)RendererAgg_draw_lines, METH_VARARGS},
764+
{ "draw_text", (PyCFunction)RendererAgg_draw_text, METH_VARARGS, RendererAgg_draw_text__doc__},
765+
{ "write_rgba", (PyCFunction)RendererAgg_write_rgba, METH_VARARGS},
766+
{ "write_png", (PyCFunction)RendererAgg_write_png, METH_VARARGS},
767+
{ "rgb", (PyCFunction)RendererAgg_rgb, METH_VARARGS, RendererAgg_rgb__doc__ },
768+
{ "rgba", (PyCFunction)RendererAgg_rgba, METH_VARARGS, RendererAgg_rgba__doc__ },
769+
710770
{NULL, NULL} /* sentinel */
711771
};
712772

@@ -805,6 +865,7 @@ static PyTypeObject RendererAgg_Type = {
805865

806866
static PyMethodDef _backend_agg_methods[] = {
807867
{"RendererAgg", _backend_agg_new_renderer, METH_VARARGS},
868+
{ "Font", (PyCFunction)agg_font, METH_VARARGS, agg_font__doc__ },
808869
{NULL, NULL} /* sentinel */
809870
};
810871

@@ -818,6 +879,7 @@ DL_EXPORT(void)
818879
/* Initialize the type of the new type object here; doing it here
819880
* is required for portability to Windows without requiring C++. */
820881
RendererAgg_Type.ob_type = &PyType_Type;
882+
Font_Type.ob_type = &PyType_Type;
821883

822884
/* Create the module and add the functions */
823885
module = Py_InitModule("_backend_agg", _backend_agg_methods);

0 commit comments

Comments
 (0)
0