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

Skip to content

Commit 9b9e063

Browse files
committed
some support for path based clipping
svn path=/trunk/matplotlib/; revision=3093
1 parent ae347ec commit 9b9e063

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

examples/clippath_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@
77
t = nx.arange(0.0, 4.0, 0.01)
88
s = 2*nx.sin(2*nx.pi*8*t)
99
line, = ax.plot(t, s)
10-
line2, = ax.plot(t, 0.5*s)
11-
line3, = ax.plot(t, 4*s)
10+
line2, = ax.plot(t, 0.5*s, '--')
11+
1212
markers, = ax.plot(t, 2*(nx.mlab.rand(len(t))-0.5), 'bo')
1313
path = agg.path_storage()
14-
poly = RegularPolygon( (2, 0.), numVertices=8, radius=1.5)
14+
poly = RegularPolygon( (2, 0.), numVertices=100, radius=1.5)
1515
#for i, xy in enumerate(ax.transData.seq_xy_tups(poly.get_verts())):
1616
for i, xy in enumerate(ax.transData.seq_xy_tups(poly.get_verts())):
1717
if i==0: path.move_to(*xy)
1818
else: path.line_to(*xy)
1919
path.close_polygon()
2020
line.set_clip_path(path)
2121
line2.set_clip_path(path)
22-
line3.set_clip_path(path)
2322
show()

examples/polar_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from pylab import *
4343

4444
# radar green, solid grid lines
45-
rc('grid', color='#316931', linewidth=1, linestyle='-')
45+
rc('grid', color='red', linewidth=1, linestyle='-')
4646
rc('xtick', labelsize=15)
4747
rc('ytick', labelsize=15)
4848
# force square figure and square axes looks better for polar, IMO
@@ -54,5 +54,5 @@
5454
polar(theta, r, color='#ee8d18', lw=3)
5555

5656
title("And there was much rejoicing!", fontsize=20)
57-
savefig('polar_demo')
57+
#savefig('polar_demo')
5858
show()

lib/matplotlib/axes.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
typecode, concatenate, newaxis, reshape, resize, repeat, cross_correlate, nonzero
1010

1111
import numerix.ma as ma
12-
12+
import matplotlib.numerix as nx
1313
import matplotlib.mlab
1414
import matplotlib.agg as agg
1515
import artist
@@ -5109,6 +5109,8 @@ def set_rgrids(self, radii, labels=None, angle=22.5, **kwargs):
51095109
for r in radii:
51105110
r = ones(self.RESOLUTION)*r
51115111
line = Line2D(theta, r, linestyle=ls, color=color, linewidth=lw)
5112+
#line = Line2D(nx.mlab.rand(len(theta)), nx.mlab.rand(len(theta)),
5113+
# linestyle=ls, color=color, linewidth=lw)
51125114
line.set_transform(self.transData)
51135115
self.rgridlines.append(line)
51145116

@@ -5231,8 +5233,7 @@ def make_clippath():
52315233

52325234
for line in self.lines:
52335235
#line.set_clip_path(make_clippath())
5234-
#line.set_clip_path(clippath)
5235-
pass
5236+
line.set_clip_path(clippath)
52365237

52375238
for t in self.thetagridlabels+self.rgridlabels:
52385239
t.draw(renderer)
@@ -5250,6 +5251,9 @@ def make_clippath():
52505251
a.draw(renderer)
52515252

52525253
self.title.draw(renderer)
5254+
5255+
5256+
52535257
self.transData.thaw() # release the lazy objects
52545258
self.transAxes.thaw() # release the lazy objects
52555259
renderer.close_group('polar_axes')

src/_backend_agg.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,8 +1439,9 @@ RendererAgg::draw_lines(const Py::Tuple& args) {
14391439
double lastx(-2.0), lasty(-2.0);
14401440

14411441
size_t i(0);
1442+
bool more(true);
14421443
for (i=0; i<Nx; i++) {
1443-
1444+
more = true;
14441445
thisx = *(double *)(xa->data + i*xa->strides[0]);
14451446
thisy = *(double *)(ya->data + i*ya->strides[0]);
14461447

@@ -1487,9 +1488,11 @@ RendererAgg::draw_lines(const Py::Tuple& args) {
14871488
moveto = false;
14881489
if ((i>0) & (i%10000)==0) {
14891490
//draw the path in chunks
1491+
//std::cout << "rendering chunk " << i << std::endl;
14901492
_render_lines_path(path, gc);
14911493
path.remove_all();
14921494
path.move_to(thisx, thisy);
1495+
more = false;
14931496
}
14941497

14951498

@@ -1502,8 +1505,9 @@ RendererAgg::draw_lines(const Py::Tuple& args) {
15021505
//typedef agg::conv_transform<agg::path_storage, agg::trans_affine> path_t;
15031506
//path_t transpath(path, xytrans);
15041507
_VERBOSE("RendererAgg::draw_lines rendering lines path");
1505-
if ((i>0) & ((i%10000)!=0)) {
1508+
if (more){
15061509
//render the rest
1510+
///std::cout << "rendering the rest" << std::endl;
15071511
_render_lines_path(path, gc);
15081512
}
15091513

@@ -1520,11 +1524,11 @@ RendererAgg::_process_alpha_mask(const GCAgg& gc)
15201524
if (gc.clippath==NULL) {
15211525
return false;
15221526
}
1523-
if (gc.clippath==lastclippath) {
1527+
if (0 &(gc.clippath==lastclippath)) {
15241528
//std::cout << "seen it" << std::endl;
15251529
return true;
15261530
}
1527-
rendererBaseAlphaMask->clear(agg::gray8(0,0));
1531+
rendererBaseAlphaMask->clear(agg::gray8(0, 0));
15281532
gc.clippath->rewind(0);
15291533
theRasterizer->add_path(*(gc.clippath));
15301534
rendererAlphaMask->color(agg::gray8(255,255));
@@ -1576,6 +1580,7 @@ RendererAgg::_render_lines_path(PathSource &path, const GCAgg& gc) {
15761580
typedef agg::renderer_scanline_aa_solid<amask_ren_type> renderer_type;
15771581
renderer_type ren(r);
15781582
ren.color(gc.color);
1583+
//std::cout << "render clippath" << std::endl;
15791584
agg::render_scanlines(*theRasterizer, *slineP8, ren);
15801585
}
15811586
else {

0 commit comments

Comments
 (0)