Skip to content

Commit 87b8098

Browse files
committed
used seq proto in collection agg methods
svn path=/trunk/matplotlib/; revision=981
1 parent 9979d2b commit 87b8098

File tree

7 files changed

+52
-64
lines changed

7 files changed

+52
-64
lines changed

CHANGELOG

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
New entries should be added at the top
22

3-
2005-02-121 fixed ps color bug - JDH
3+
2005-02-23 Used sequence protocol rather than tuple in agg collection
4+
drawing routines for greater flexibility - JDH
5+
6+
7+
===========================================================
8+
2005-02-22 0.72.1 released
9+
10+
2005-02-21 fixed linestyles for collections -- contour now dashes for
11+
levels <0
12+
13+
2005-02-21 fixed ps color bug - JDH
414

515
2005-02-15 fixed missing qt file
616

lib/matplotlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"""
142142
from __future__ import generators
143143

144-
__version__ = '0.72'
144+
__version__ = '0.73'
145145
__revision__ = '$Revision$'
146146
__date__ = '$Date$'
147147

lib/matplotlib/axes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,10 +1185,8 @@ def initialize_reg_tri(z):
11851185
col = LineCollection(nlist)
11861186
col.set_color(color)
11871187
col.set_linewidth(width)
1188-
"""
11891188
if level < 0:
11901189
col.set_linestyle((0, (6.,6.)),)
1191-
"""
11921190
col.set_label(fmt%level)
11931191
self.add_collection(col)
11941192
levels.append(level)

lib/matplotlib/collections.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,12 @@ def set_alpha(self, alpha):
395395
def get_linewidths(self):
396396
return self._lw
397397

398+
def get_linestyle(self):
399+
return self._ls
400+
401+
def get_dashes(self):
402+
return self._ls
403+
398404
def get_colors(self):
399405
return self._colors
400406

lib/matplotlib/legend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,11 @@ def _get_handles(self, handles, texts):
237237
self._set_artist_props(legline)
238238
legline.set_clip_box(None)
239239
lw = handle.get_linewidths()[0]
240-
style = handle.get_linewidths()[0]
240+
dashes = handle.get_dashes()
241241
color = handle.get_colors()[0]
242242
legline.set_color(color)
243243
legline.set_linewidth(lw)
244+
legline.set_dashes(dashes)
244245
ret.append(legline)
245246

246247
else:

lib/matplotlib/lines.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ def __init__(self, xdata, ydata,
139139
raise ValueError('Unrecognized marker style %s, %s'%( marker, type(marker)))
140140

141141
self.set_marker(marker)
142-
self._lineFunc = self._lineStyles.get(linestyle, self._draw_nothing)
143-
self._markerFunc = self._markers.get(marker, self._draw_nothing)
144142

145143
self._logcache = None
146144

@@ -280,7 +278,8 @@ def draw(self, renderer):
280278
xt, yt = self._transform.numerix_x_y(x, y)
281279

282280

283-
lineFunc = getattr(self, self._lineFunc)
281+
funcname = self._lineStyles.get(self._linestyle, '_draw_nothing')
282+
lineFunc = getattr(self, funcname)
284283
lineFunc(renderer, gc, xt, yt)
285284

286285

@@ -290,7 +289,8 @@ def draw(self, renderer):
290289
gc.set_linewidth(self._markeredgewidth)
291290
if self.get_clip_on():
292291
gc.set_clip_rectangle(self.clipbox.get_bounds())
293-
markerFunc = getattr(self, self._markerFunc)
292+
funcname = self._markers.get(self._marker, '_draw_nothing')
293+
markerFunc = getattr(self, funcname)
294294
markerFunc(renderer, gc, xt, yt)
295295

296296
#if 1: bbox_artist(self, renderer)
@@ -395,7 +395,7 @@ def set_linestyle(self, s):
395395
ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
396396
"""
397397
self._linestyle = s
398-
self._lineFunc = self._lineStyles.get(self._linestyle, '-')
398+
399399

400400
def set_marker(self, marker):
401401
"""
@@ -405,7 +405,6 @@ def set_marker(self, marker):
405405
406406
"""
407407
self._marker = marker
408-
self._markerFunc = self._markers.get(marker, self._draw_nothing)
409408

410409
def set_markeredgecolor(self, ec):
411410
"""
@@ -497,7 +496,11 @@ def set_dashes(self, seq):
497496
498497
ACCEPTS: sequence of on/off ink in points
499498
"""
500-
self._dashSeq = seq
499+
if seq == (None, None):
500+
self.set_linestyle('-')
501+
else:
502+
self.set_linestyle('--')
503+
self._dashSeq = seq[1] # TODO: offset ignroed for now
501504

502505
def _draw_nothing(self, renderer, gc, xt, yt):
503506
pass
@@ -1055,8 +1058,6 @@ def update_from(self, other):
10551058

10561059
self._linestyle = other._linestyle
10571060
self._marker = other._marker
1058-
self._lineFunc = other._lineStyles[other._linestyle]
1059-
self._markerFunc = other._markers[other._marker]
10601061
self._useDataClipping = other._useDataClipping
10611062

10621063
def _get_rgb_face(self):

src/_backend_agg.cpp

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,6 @@ RendererAgg::draw_line_collection(const Py::Tuple& args) {
391391
//segments, trans, clipbox, colors, linewidths, antialiaseds
392392
Py::SeqBase<Py::Object> segments = args[0];
393393

394-
/* this line is broken, mysteriously
395-
if (!Transformation::check(args[1]))
396-
throw Py::TypeError("RendererAgg::draw_line_collection(segments, transform, ...) expected a Transformation instance for transform");
397-
398-
*/
399-
400394
Transformation* transform = static_cast<Transformation*>(args[1].ptr());
401395

402396
set_clip_from_bbox(args[2]);
@@ -420,8 +414,9 @@ RendererAgg::draw_line_collection(const Py::Tuple& args) {
420414
size_t Naa = antialiaseds.length();
421415
size_t Noffsets = 0;
422416
size_t N = Nsegments;
417+
size_t Ndash = 0;
423418

424-
Py::Tuple dashtup(linestyle);
419+
Py::SeqBase<Py::Object> dashtup(linestyle);
425420
bool useDashes = dashtup[0].ptr() != Py_None;
426421

427422
double offset = 0;
@@ -435,14 +430,14 @@ RendererAgg::draw_line_collection(const Py::Tuple& args) {
435430
offset = points_to_pixels_snapto(dashtup[0]);
436431
dashSeq = dashtup[1];
437432

438-
size_t N = dashSeq.length();
439-
if (N%2 != 0 )
433+
Ndash = dashSeq.length();
434+
if (Ndash%2 != 0 )
440435
throw Py::ValueError(Printf("dashes must be an even length sequence; found %d", N).str());
441436

442-
dasha = new double[N];
437+
dasha = new double[Ndash];
443438

444-
for (size_t i=0; i<N; i++)
445-
dasha[i] = points_to_pixels_snapto(dashSeq[i]);
439+
for (size_t i=0; i<Ndash; i++)
440+
dasha[i] = points_to_pixels(dashSeq[i]);
446441
}
447442

448443

@@ -453,11 +448,11 @@ RendererAgg::draw_line_collection(const Py::Tuple& args) {
453448

454449
double xo(0.0), yo(0.0), thisx(0.0), thisy(0.0);
455450
std::pair<double, double> xy;
456-
Py::Tuple xyo;
451+
Py::SeqBase<Py::Object> xyo;
457452
Py::SeqBase<Py::Object> xys;
458453
for (size_t i=0; i<N; ++i) {
459454
if (usingOffsets) {
460-
xyo = Py::Tuple(offsets[i%Noffsets]);
455+
xyo = Py::SeqBase<Py::Object>(offsets[i%Noffsets]);
461456
xo = Py::Float(xyo[0]);
462457
yo = Py::Float(xyo[1]);
463458
try {
@@ -516,32 +511,9 @@ RendererAgg::draw_line_collection(const Py::Tuple& args) {
516511
}
517512
else {
518513

519-
/*
520-
size_t N = dashSeq.length();
521-
if (N%2 != 0 )
522-
throw Py::ValueError(Printf("dashes must be an even length sequence; found %d", N).str());
523-
524-
typedef agg::conv_dash<agg::path_storage> dash_t;
525-
dash_t dash(path);
526-
527-
double on, off;
528-
529-
//dash.dash_start(offset);
530-
for (size_t i=0; i<N/2; i+=1) {
531-
on = points_to_pixels_snapto(dashSeq[2*i]);
532-
off = points_to_pixels_snapto(dashSeq[2*i+1]);
533-
dash.add_dash(on, off);
534-
}
535-
agg::conv_stroke<dash_t> stroke(dash);
536-
stroke.line_cap(cap);
537-
stroke.line_join(join);
538-
stroke.width(lw);
539-
theRasterizer->add_path(stroke);
540-
541-
*/
542514
dash_t dash(path);
543515
//dash.dash_start(offset);
544-
for (size_t idash=0; idash<N/2; idash++)
516+
for (size_t idash=0; idash<Ndash/2; idash++)
545517
dash.add_dash(dasha[2*idash], dasha[2*idash+1]);
546518

547519
agg::conv_stroke<dash_t> stroke(dash);
@@ -552,7 +524,7 @@ RendererAgg::draw_line_collection(const Py::Tuple& args) {
552524
}
553525

554526
// get the color and render
555-
Py::Tuple rgba = Py::Tuple(colors[ i%Nc]);
527+
Py::SeqBase<Py::Object> rgba(colors[ i%Nc]);
556528
double r = Py::Float(rgba[0]);
557529
double g = Py::Float(rgba[1]);
558530
double b = Py::Float(rgba[2]);
@@ -650,13 +622,13 @@ RendererAgg::draw_poly_collection(const Py::Tuple& args) {
650622
size_t N = (Noffsets>Nverts) ? Noffsets : Nverts;
651623

652624
std::pair<double, double> xyo, xy;
653-
Py::Tuple thisverts;
625+
Py::SeqBase<Py::Object> thisverts;
654626
for (size_t i=0; i<N; ++i) {
655627

656628
thisverts = verts[i % Nverts];
657629

658630
if (usingOffsets) {
659-
Py::Tuple pos = Py::Tuple(offsets[i]);
631+
Py::SeqBase<Py::Object> pos = Py::SeqBase<Py::Object>(offsets[i]);
660632
double xo = Py::Float(pos[0]);
661633
double yo = Py::Float(pos[1]);
662634
try {
@@ -671,14 +643,14 @@ RendererAgg::draw_poly_collection(const Py::Tuple& args) {
671643
size_t Nverts = thisverts.length();
672644
agg::path_storage path;
673645

674-
Py::Tuple thisvert;
646+
Py::SeqBase<Py::Object> thisvert;
675647

676648

677649
// dump the verts to double arrays so we can do more efficient
678650
// look aheads and behinds when doing snapto pixels
679651
double xs[Nverts], ys[Nverts];
680652
for (size_t j=0; j<Nverts; ++j) {
681-
thisvert = Py::Tuple(thisverts[j]);
653+
thisvert = thisverts[j];
682654
double x = Py::Float(thisvert[0]);
683655
double y = Py::Float(thisvert[1]);
684656
try {
@@ -730,7 +702,7 @@ RendererAgg::draw_poly_collection(const Py::Tuple& args) {
730702
path.close_polygon();
731703
int isaa = Py::Int(antialiaseds[i%Naa]);
732704
// get the facecolor and render
733-
Py::Tuple rgba = Py::Tuple(facecolors[ i%Nface]);
705+
Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(facecolors[ i%Nface]);
734706
double r = Py::Float(rgba[0]);
735707
double g = Py::Float(rgba[1]);
736708
double b = Py::Float(rgba[2]);
@@ -751,7 +723,7 @@ RendererAgg::draw_poly_collection(const Py::Tuple& args) {
751723
} //renderer face
752724

753725
// get the edgecolor and render
754-
rgba = Py::Tuple(edgecolors[ i%Nedge]);
726+
rgba = Py::SeqBase<Py::Object>(edgecolors[ i%Nedge]);
755727
r = Py::Float(rgba[0]);
756728
g = Py::Float(rgba[1]);
757729
b = Py::Float(rgba[2]);
@@ -829,16 +801,16 @@ RendererAgg::draw_regpoly_collection(const Py::Tuple& args) {
829801
// dump the x.y vertices into a double array for faster access
830802
double xverts[Nverts];
831803
double yverts[Nverts];
832-
Py::Tuple xy;
804+
Py::SeqBase<Py::Object> xy;
833805
for (size_t i=0; i<Nverts; ++i) {
834-
xy = Py::Tuple(verts[i]);
806+
xy = Py::SeqBase<Py::Object>(verts[i]);
835807
xverts[i] = Py::Float(xy[0]);
836808
yverts[i] = Py::Float(xy[1]);
837809
}
838810

839811
std::pair<double, double> offsetPair;
840812
for (size_t i=0; i<Noffsets; ++i) {
841-
Py::Tuple pos = Py::Tuple(offsets[i]);
813+
Py::SeqBase<Py::Object> pos = Py::SeqBase<Py::Object>(offsets[i]);
842814
double xo = Py::Float(pos[0]);
843815
double yo = Py::Float(pos[1]);
844816
try {
@@ -867,7 +839,7 @@ RendererAgg::draw_regpoly_collection(const Py::Tuple& args) {
867839
path.close_polygon();
868840
int isaa = Py::Int(antialiaseds[i%Naa]);
869841
// get the facecolor and render
870-
Py::Tuple rgba = Py::Tuple(facecolors[ i%Nface]);
842+
Py::SeqBase<Py::Object> rgba = Py::SeqBase<Py::Object>(facecolors[ i%Nface]);
871843
double r = Py::Float(rgba[0]);
872844
double g = Py::Float(rgba[1]);
873845
double b = Py::Float(rgba[2]);
@@ -888,7 +860,7 @@ RendererAgg::draw_regpoly_collection(const Py::Tuple& args) {
888860
} //renderer face
889861

890862
// get the edgecolor and render
891-
rgba = Py::Tuple(edgecolors[ i%Nedge]);
863+
rgba = Py::SeqBase<Py::Object>(edgecolors[ i%Nedge]);
892864
r = Py::Float(rgba[0]);
893865
g = Py::Float(rgba[1]);
894866
b = Py::Float(rgba[2]);

0 commit comments

Comments
 (0)