Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit73d28ee

Browse files
Addrasterized option tocontourf (#29582)
* allow rasterization* use rasterized kwarg* add to documentation* Fix copied docstringCo-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>* first pass at test* add image comparison---------Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
1 parent3edda65 commit73d28ee

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

‎lib/matplotlib/contour.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
importmatplotlib.cbookascbook
2525
importmatplotlib.patchesasmpatches
2626
importmatplotlib.transformsasmtransforms
27+
from .importartist
2728

2829

2930
def_contour_labeler_event_handler(cs,inline,inline_spacing,event):
@@ -767,6 +768,7 @@ def __init__(self, ax, *args,
767768
edgecolor="none",
768769
# Default zorder taken from Collection
769770
zorder=kwargs.pop("zorder",1),
771+
rasterized=kwargs.pop("rasterized",False),
770772
)
771773

772774
else:
@@ -1254,6 +1256,7 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
12541256

12551257
return (i_level,segment,index,xmin,ymin,d2)
12561258

1259+
@artist.allow_rasterization
12571260
defdraw(self,renderer):
12581261
paths=self._paths
12591262
n_paths=len(paths)
@@ -1681,6 +1684,13 @@ def _initialize_x_y(self, z):
16811684
data : indexable object, optional
16821685
DATA_PARAMETER_PLACEHOLDER
16831686
1687+
rasterized : bool, optional
1688+
*Only applies to* `.contourf`.
1689+
Rasterize the contour plot when drawing vector graphics. This can
1690+
speed up rendering and produce smaller files for large data sets.
1691+
See also :doc:`/gallery/misc/rasterization_demo`.
1692+
1693+
16841694
Notes
16851695
-----
16861696
1. `.contourf` differs from the MATLAB version in that it does not draw
Binary file not shown.

‎lib/matplotlib/tests/test_contour.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,3 +837,13 @@ def test_allsegs_allkinds():
837837
assertlen(result)==2
838838
assertlen(result[0])==5
839839
assertlen(result[1])==4
840+
841+
842+
@image_comparison(baseline_images=['contour_rasterization'],
843+
extensions=['pdf'],style='mpl20',savefig_kwarg={'dpi':25})
844+
deftest_contourf_rasterize():
845+
fig,ax=plt.subplots()
846+
data= [[0,1], [1,0]]
847+
circle=mpatches.Circle([0.5,0.5],0.5,transform=ax.transAxes)
848+
cs=ax.contourf(data,clip_path=circle,rasterized=True)
849+
assertcs._rasterized

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp