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

Skip to content

Commit 134c06a

Browse files
authored
Merge pull request #8957 from kbrose/performance-helpers
DOC: New style for fast plotting, updated performance docs
2 parents a226171 + 3c27100 commit 134c06a

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# a small set of changes that will make your plotting FAST (1).
2+
#
3+
# (1) in some cases
4+
5+
# Maximally simplify lines.
6+
path.simplify: True
7+
path.simplify_threshold: 1.0
8+
9+
# chunk up large lines into smaller lines!
10+
# simple trick to avoid those pesky O(>n) algorithms!
11+
agg.path.chunksize: 10000

lib/matplotlib/path.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class Path(object):
7070
*codes* at all, but have a default one provided for them by
7171
:meth:`iter_segments`.
7272
73+
Some behavior of Path objects can be controlled by rcParams. See
74+
the rcParams whose keys contain 'path.'.
75+
7376
.. note::
7477
7578
The vertices and codes arrays should be treated as
@@ -404,7 +407,8 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
404407
If True, perform simplification, to remove
405408
vertices that do not affect the appearance of the path. If
406409
False, perform no simplification. If None, use the
407-
should_simplify member variable.
410+
should_simplify member variable. See also the rcParams
411+
path.simplify and path.simplify_threshold.
408412
curves : {True, False}, optional
409413
If True, curve segments will be returned as curve
410414
segments. If False, all curves will be converted to line

tutorials/introductory/usage.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,3 +714,58 @@ def my_plotter(ax, data1, data2, param_dict):
714714
# attempt at evenly spaced (along the *x* axis) sampling. See the
715715
# :ref:`sphx_glr_gallery_lines_bars_and_markers_markevery_demo.py`
716716
# for more information.
717+
#
718+
# Splitting lines into smaller chunks
719+
# -----------------------------------
720+
#
721+
# If you are using the Agg backend (see :ref:`what-is-a-backend`),
722+
# then you can make use of the ``agg.path.chunksize`` rc parameter.
723+
# This allows you to specify a chunk size, and any lines with
724+
# greater than that many vertices will be split into multiple
725+
# lines, each of which have no more than ``agg.path.chunksize``
726+
# many vertices. (Unless ``agg.path.chunksize`` is zero, in
727+
# which case there is no chunking.) For some kind of data,
728+
# chunking the line up into reasonable sizes can greatly
729+
# decrease rendering time.
730+
#
731+
# The following script will first display the data without any
732+
# chunk size restriction, and then display the same data with
733+
# a chunk size of 10,000. The difference can best be seen when
734+
# the figures are large, try maximizing the GUI and then
735+
# interacting with them::
736+
#
737+
# import numpy as np
738+
# import matplotlib.pyplot as plt
739+
# import matplotlib as mpl
740+
# mpl.rcParams['path.simplify_threshold'] = 1.0
741+
#
742+
# # Setup, and create the data to plot
743+
# y = np.random.rand(100000)
744+
# y[50000:] *= 2
745+
# y[np.logspace(1,np.log10(50000), 400).astype(int)] = -1
746+
# mpl.rcParams['path.simplify'] = True
747+
#
748+
# mpl.rcParams['agg.path.chunksize'] = 0
749+
# plt.plot(y)
750+
# plt.show()
751+
#
752+
# mpl.rcParams['agg.path.chunksize'] = 10000
753+
# plt.plot(y)
754+
# plt.show()
755+
#
756+
# Using the *fast* style
757+
# ----------------------
758+
#
759+
# The *fast* style can be used to automatically set
760+
# simplification and chunking parameters to reasonable
761+
# settings to speed up plotting large amounts of data.
762+
# It can be used simply by running::
763+
#
764+
# import matplotlib.style as mplstyle
765+
# mplstyle.use('fast')
766+
#
767+
# It is very light weight, so it plays nicely with other
768+
# styles, just make sure the fast style is applied last
769+
# so that other styles do not overwrite the settings::
770+
#
771+
# mplstyle.use(['dark_background', 'ggplot', 'fast'])

0 commit comments

Comments
 (0)