hc99 commited on
Commit
714e7c4
·
verified ·
1 Parent(s): d439dc1

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. testbed/matplotlib__matplotlib/ci/check_version_number.py +19 -0
  2. testbed/matplotlib__matplotlib/ci/check_wheel_licenses.py +33 -0
  3. testbed/matplotlib__matplotlib/ci/codespell-ignore-words.txt +23 -0
  4. testbed/matplotlib__matplotlib/ci/export_sdist_name.py +21 -0
  5. testbed/matplotlib__matplotlib/ci/mypy-stubtest-allowlist.txt +166 -0
  6. testbed/matplotlib__matplotlib/galleries/examples/README.txt +16 -0
  7. testbed/matplotlib__matplotlib/galleries/examples/animation/README.txt +6 -0
  8. testbed/matplotlib__matplotlib/galleries/examples/animation/animate_decay.py +59 -0
  9. testbed/matplotlib__matplotlib/galleries/examples/animation/animated_histogram.py +57 -0
  10. testbed/matplotlib__matplotlib/galleries/examples/animation/animation_demo.py +30 -0
  11. testbed/matplotlib__matplotlib/galleries/examples/animation/bayes_update.py +66 -0
  12. testbed/matplotlib__matplotlib/galleries/examples/animation/double_pendulum.py +117 -0
  13. testbed/matplotlib__matplotlib/galleries/examples/animation/dynamic_image.py +48 -0
  14. testbed/matplotlib__matplotlib/galleries/examples/animation/frame_grabbing_sgskip.py +43 -0
  15. testbed/matplotlib__matplotlib/galleries/examples/animation/multiple_axes.py +82 -0
  16. testbed/matplotlib__matplotlib/galleries/examples/animation/pause_resume.py +59 -0
  17. testbed/matplotlib__matplotlib/galleries/examples/animation/rain.py +74 -0
  18. testbed/matplotlib__matplotlib/galleries/examples/animation/random_walk.py +54 -0
  19. testbed/matplotlib__matplotlib/galleries/examples/animation/simple_anim.py +38 -0
  20. testbed/matplotlib__matplotlib/galleries/examples/animation/simple_scatter.py +33 -0
  21. testbed/matplotlib__matplotlib/galleries/examples/animation/strip_chart.py +69 -0
  22. testbed/matplotlib__matplotlib/galleries/examples/animation/unchained.py +76 -0
  23. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/README.txt +6 -0
  24. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_anchored_direction_arrows.py +82 -0
  25. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_divider.py +109 -0
  26. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_grid.py +72 -0
  27. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_grid2.py +69 -0
  28. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_hbox_divider.py +54 -0
  29. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_rgb.py +70 -0
  30. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_colorbar_of_inset_axes.py +33 -0
  31. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_colorbar_with_axes_divider.py +35 -0
  32. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_colorbar_with_inset_locator.py +43 -0
  33. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_edge_colorbar.py +86 -0
  34. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_fixed_size_axes.py +50 -0
  35. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_imagegrid_aspect.py +23 -0
  36. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/inset_locator_demo.py +145 -0
  37. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/inset_locator_demo2.py +73 -0
  38. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py +55 -0
  39. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/parasite_simple.py +26 -0
  40. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/parasite_simple2.py +45 -0
  41. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/scatter_hist_locatable_axes.py +77 -0
  42. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_anchored_artists.py +71 -0
  43. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axes_divider1.py +69 -0
  44. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axes_divider3.py +44 -0
  45. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axesgrid.py +29 -0
  46. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axesgrid2.py +31 -0
  47. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axisline4.py +24 -0
  48. testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_colorbar.py +22 -0
  49. testbed/matplotlib__matplotlib/galleries/examples/axisartist/README.txt +6 -0
  50. testbed/matplotlib__matplotlib/galleries/examples/axisartist/axis_direction.py +68 -0
testbed/matplotlib__matplotlib/ci/check_version_number.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Check that the version number of the install Matplotlib does not start with 0
5
+
6
+ To run:
7
+ $ python3 -m build .
8
+ $ pip install dist/matplotlib*.tar.gz for sdist
9
+ $ pip install dist/matplotlib*.whl for wheel
10
+ $ ./ci/check_version_number.py
11
+ """
12
+ import sys
13
+
14
+ import matplotlib
15
+
16
+
17
+ print(f"Version {matplotlib.__version__} installed")
18
+ if matplotlib.__version__[0] == "0":
19
+ sys.exit("Version incorrectly starts with 0")
testbed/matplotlib__matplotlib/ci/check_wheel_licenses.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Check that all specified .whl files have the correct LICENSE files included.
5
+
6
+ To run:
7
+ $ python3 -m build --wheel
8
+ $ ./ci/check_wheel_licenses.py dist/*.whl
9
+ """
10
+
11
+ from pathlib import Path
12
+ import sys
13
+ import zipfile
14
+
15
+
16
+ if len(sys.argv) <= 1:
17
+ sys.exit('At least one wheel must be specified in command-line arguments.')
18
+
19
+ project_dir = Path(__file__).parent.resolve().parent
20
+ license_dir = project_dir / 'LICENSE'
21
+
22
+ license_file_names = {path.name for path in sorted(license_dir.glob('*'))}
23
+ for wheel in sys.argv[1:]:
24
+ print(f'Checking LICENSE files in: {wheel}')
25
+ with zipfile.ZipFile(wheel) as f:
26
+ wheel_license_file_names = {Path(path).name
27
+ for path in sorted(f.namelist())
28
+ if '.dist-info/LICENSE' in path}
29
+ if not (len(wheel_license_file_names) and
30
+ wheel_license_file_names.issuperset(license_file_names)):
31
+ sys.exit(f'LICENSE file(s) missing:\n'
32
+ f'{wheel_license_file_names} !=\n'
33
+ f'{license_file_names}')
testbed/matplotlib__matplotlib/ci/codespell-ignore-words.txt ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ans
2
+ axises
3
+ ba
4
+ cannotation
5
+ ccompiler
6
+ coo
7
+ curvelinear
8
+ dedented
9
+ falsy
10
+ flate
11
+ fpt
12
+ hax
13
+ hist
14
+ inh
15
+ inout
16
+ ment
17
+ nd
18
+ oly
19
+ resizeable
20
+ te
21
+ thisy
22
+ whis
23
+ wit
testbed/matplotlib__matplotlib/ci/export_sdist_name.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Determine the name of the sdist and export to GitHub output named SDIST_NAME.
5
+
6
+ To run:
7
+ $ python3 -m build --sdist
8
+ $ ./ci/determine_sdist_name.py
9
+ """
10
+ import os
11
+ from pathlib import Path
12
+ import sys
13
+
14
+
15
+ paths = [p.name for p in Path("dist").glob("*.tar.gz")]
16
+ if len(paths) != 1:
17
+ sys.exit(f"Only a single sdist is supported, but found: {paths}")
18
+
19
+ print(paths[0])
20
+ with open(os.environ["GITHUB_OUTPUT"], "a") as f:
21
+ f.write(f"SDIST_NAME={paths[0]}\n")
testbed/matplotlib__matplotlib/ci/mypy-stubtest-allowlist.txt ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Non-typed (and private) modules/functions
2
+ matplotlib.backends.*
3
+ matplotlib.tests.*
4
+ matplotlib.pylab.*
5
+ matplotlib._.*
6
+ matplotlib.rcsetup._listify_validator
7
+ matplotlib.rcsetup._validate_linestyle
8
+ matplotlib.ft2font.Glyph
9
+ matplotlib.testing.jpl_units.*
10
+ matplotlib.sphinxext.*
11
+
12
+ # set methods have heavy dynamic usage of **kwargs, with differences for subclasses
13
+ # which results in technically inconsistent signatures, but not actually a problem
14
+ matplotlib.*\.set$
15
+
16
+ # Typed inline, inconsistencies largely due to imports
17
+ matplotlib.pyplot.*
18
+ matplotlib.typing.*
19
+
20
+ # Other decorator modifying signature
21
+ # Runtime picks up *args **kwargs, but only decorated by a decorator that uses @wraps so?
22
+ matplotlib.axis.Axis.draw
23
+ # Backcompat decorator which does not modify runtime reported signature
24
+ matplotlib.offsetbox.*Offset[Bb]ox.get_offset
25
+
26
+ # Inconsistent super/sub class parameter name (maybe rename for consistency)
27
+ matplotlib.projections.polar.RadialLocator.nonsingular
28
+ matplotlib.ticker.LogLocator.nonsingular
29
+ matplotlib.ticker.LogitLocator.nonsingular
30
+
31
+ # Stdlib/Enum considered inconsistent (no fault of ours, I don't think)
32
+ matplotlib.backend_bases._Mode.__new__
33
+ matplotlib.units.Number.__hash__
34
+
35
+ # Property read-write vs read-only weirdness, fix if possible
36
+ matplotlib.offsetbox.DraggableBase.canvas
37
+ matplotlib.offsetbox.DraggableBase.cids
38
+ matplotlib.transforms.BboxTransform.is_separable
39
+ matplotlib.transforms.BboxTransformFrom.is_separable
40
+ matplotlib.transforms.BboxTransformTo.is_separable
41
+ matplotlib.transforms.BlendedAffine2D.is_separable
42
+ matplotlib.transforms.CompositeGenericTransform.is_separable
43
+ matplotlib.transforms.TransformWrapper.input_dims
44
+ matplotlib.transforms.TransformWrapper.is_separable
45
+ matplotlib.transforms.TransformWrapper.output_dims
46
+
47
+ # 3.6 Pending deprecations
48
+ matplotlib.figure.Figure.set_constrained_layout
49
+ matplotlib.figure.Figure.set_constrained_layout_pads
50
+ matplotlib.figure.Figure.set_tight_layout
51
+
52
+ # 3.7 deprecations
53
+ matplotlib.cm.register_cmap
54
+ matplotlib.cm.unregister_cmap
55
+ matplotlib.collections.PolyCollection.span_where
56
+ matplotlib.gridspec.GridSpecBase.get_grid_positions
57
+ matplotlib.widgets.MultiCursor.needclear
58
+
59
+ # 3.8 deprecations
60
+ matplotlib.cbook.get_sample_data
61
+ matplotlib.contour.ContourSet.allkinds
62
+ matplotlib.contour.ContourSet.allsegs
63
+ matplotlib.contour.ContourSet.tcolors
64
+ matplotlib.contour.ContourSet.tlinewidths
65
+ matplotlib.ticker.LogLocator.__init__
66
+ matplotlib.ticker.LogLocator.set_params
67
+
68
+ # positional-only argument name lacking leading underscores
69
+ matplotlib.axes._base._AxesBase.axis
70
+
71
+ # Aliases (dynamically generated, not type hinted)
72
+ matplotlib.collections.Collection.get_aa
73
+ matplotlib.collections.Collection.get_antialiaseds
74
+ matplotlib.collections.Collection.get_dashes
75
+ matplotlib.collections.Collection.get_ec
76
+ matplotlib.collections.Collection.get_edgecolors
77
+ matplotlib.collections.Collection.get_facecolors
78
+ matplotlib.collections.Collection.get_fc
79
+ matplotlib.collections.Collection.get_linestyles
80
+ matplotlib.collections.Collection.get_linewidths
81
+ matplotlib.collections.Collection.get_ls
82
+ matplotlib.collections.Collection.get_lw
83
+ matplotlib.collections.Collection.get_transOffset
84
+ matplotlib.collections.Collection.set_aa
85
+ matplotlib.collections.Collection.set_antialiaseds
86
+ matplotlib.collections.Collection.set_dashes
87
+ matplotlib.collections.Collection.set_ec
88
+ matplotlib.collections.Collection.set_edgecolors
89
+ matplotlib.collections.Collection.set_facecolors
90
+ matplotlib.collections.Collection.set_fc
91
+ matplotlib.collections.Collection.set_linestyles
92
+ matplotlib.collections.Collection.set_linewidths
93
+ matplotlib.collections.Collection.set_ls
94
+ matplotlib.collections.Collection.set_lw
95
+ matplotlib.collections.Collection.set_transOffset
96
+ matplotlib.lines.Line2D.get_aa
97
+ matplotlib.lines.Line2D.get_c
98
+ matplotlib.lines.Line2D.get_ds
99
+ matplotlib.lines.Line2D.get_ls
100
+ matplotlib.lines.Line2D.get_lw
101
+ matplotlib.lines.Line2D.get_mec
102
+ matplotlib.lines.Line2D.get_mew
103
+ matplotlib.lines.Line2D.get_mfc
104
+ matplotlib.lines.Line2D.get_mfcalt
105
+ matplotlib.lines.Line2D.get_ms
106
+ matplotlib.lines.Line2D.set_aa
107
+ matplotlib.lines.Line2D.set_c
108
+ matplotlib.lines.Line2D.set_ds
109
+ matplotlib.lines.Line2D.set_ls
110
+ matplotlib.lines.Line2D.set_lw
111
+ matplotlib.lines.Line2D.set_mec
112
+ matplotlib.lines.Line2D.set_mew
113
+ matplotlib.lines.Line2D.set_mfc
114
+ matplotlib.lines.Line2D.set_mfcalt
115
+ matplotlib.lines.Line2D.set_ms
116
+ matplotlib.patches.Patch.get_aa
117
+ matplotlib.patches.Patch.get_ec
118
+ matplotlib.patches.Patch.get_fc
119
+ matplotlib.patches.Patch.get_ls
120
+ matplotlib.patches.Patch.get_lw
121
+ matplotlib.patches.Patch.set_aa
122
+ matplotlib.patches.Patch.set_ec
123
+ matplotlib.patches.Patch.set_fc
124
+ matplotlib.patches.Patch.set_ls
125
+ matplotlib.patches.Patch.set_lw
126
+ matplotlib.text.Text.get_c
127
+ matplotlib.text.Text.get_family
128
+ matplotlib.text.Text.get_font
129
+ matplotlib.text.Text.get_font_properties
130
+ matplotlib.text.Text.get_ha
131
+ matplotlib.text.Text.get_name
132
+ matplotlib.text.Text.get_size
133
+ matplotlib.text.Text.get_style
134
+ matplotlib.text.Text.get_va
135
+ matplotlib.text.Text.get_variant
136
+ matplotlib.text.Text.get_weight
137
+ matplotlib.text.Text.set_c
138
+ matplotlib.text.Text.set_family
139
+ matplotlib.text.Text.set_font
140
+ matplotlib.text.Text.set_font_properties
141
+ matplotlib.text.Text.set_ha
142
+ matplotlib.text.Text.set_ma
143
+ matplotlib.text.Text.set_name
144
+ matplotlib.text.Text.set_size
145
+ matplotlib.text.Text.set_stretch
146
+ matplotlib.text.Text.set_style
147
+ matplotlib.text.Text.set_va
148
+ matplotlib.text.Text.set_variant
149
+ matplotlib.text.Text.set_weight
150
+ matplotlib.axes._base._AxesBase.get_fc
151
+ matplotlib.axes._base._AxesBase.set_fc
152
+
153
+ # Other dynamic python behaviors not type hinted
154
+ matplotlib.rcsetup.defaultParams
155
+
156
+ # Maybe should be abstractmethods, required for subclasses, stubs define once
157
+ matplotlib.tri.*TriInterpolator.__call__
158
+ matplotlib.tri.*TriInterpolator.gradient
159
+
160
+ # Functionally a method call, but actually a class instance, type hinted as former
161
+ matplotlib.rcsetup.validate_fillstyle
162
+
163
+ # TypeVar used only in type hints
164
+ matplotlib.backend_bases.FigureCanvasBase._T
165
+ matplotlib.backend_managers.ToolManager._T
166
+ matplotlib.spines.Spine._T
testbed/matplotlib__matplotlib/galleries/examples/README.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .. _examples-index:
3
+
4
+ .. _gallery:
5
+
6
+ ========
7
+ Examples
8
+ ========
9
+ For an overview of the plotting methods we provide, see :ref:`plot_types`
10
+
11
+ This page contains example plots. Click on any image to see the full image
12
+ and source code.
13
+
14
+ For longer tutorials, see our :ref:`tutorials page <tutorials>`.
15
+ You can also find :ref:`external resources <resources-index>` and
16
+ a :ref:`FAQ <faq-index>` in our :ref:`user guide <users-guide-index>`.
testbed/matplotlib__matplotlib/galleries/examples/animation/README.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ .. _animation_examples:
2
+
3
+ .. _animation-examples-index:
4
+
5
+ Animation
6
+ =========
testbed/matplotlib__matplotlib/galleries/examples/animation/animate_decay.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =====
3
+ Decay
4
+ =====
5
+
6
+ This example showcases:
7
+
8
+ - using a generator to drive an animation,
9
+ - changing axes limits during an animation.
10
+
11
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
12
+ """
13
+
14
+ import itertools
15
+
16
+ import matplotlib.pyplot as plt
17
+ import numpy as np
18
+
19
+ import matplotlib.animation as animation
20
+
21
+
22
+ def data_gen():
23
+ for cnt in itertools.count():
24
+ t = cnt / 10
25
+ yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
26
+
27
+
28
+ def init():
29
+ ax.set_ylim(-1.1, 1.1)
30
+ ax.set_xlim(0, 1)
31
+ del xdata[:]
32
+ del ydata[:]
33
+ line.set_data(xdata, ydata)
34
+ return line,
35
+
36
+ fig, ax = plt.subplots()
37
+ line, = ax.plot([], [], lw=2)
38
+ ax.grid()
39
+ xdata, ydata = [], []
40
+
41
+
42
+ def run(data):
43
+ # update the data
44
+ t, y = data
45
+ xdata.append(t)
46
+ ydata.append(y)
47
+ xmin, xmax = ax.get_xlim()
48
+
49
+ if t >= xmax:
50
+ ax.set_xlim(xmin, 2*xmax)
51
+ ax.figure.canvas.draw()
52
+ line.set_data(xdata, ydata)
53
+
54
+ return line,
55
+
56
+ # Only save last 100 frames, but run forever
57
+ ani = animation.FuncAnimation(fig, run, data_gen, interval=100, init_func=init,
58
+ save_count=100)
59
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/animated_histogram.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================
3
+ Animated histogram
4
+ ==================
5
+
6
+ Use histogram's `.BarContainer` to draw a bunch of rectangles for an animated
7
+ histogram.
8
+ """
9
+
10
+ import matplotlib.pyplot as plt
11
+ import numpy as np
12
+
13
+ import matplotlib.animation as animation
14
+
15
+ # Fixing random state for reproducibility
16
+ np.random.seed(19680801)
17
+ # Fixing bin edges
18
+ HIST_BINS = np.linspace(-4, 4, 100)
19
+
20
+ # histogram our data with numpy
21
+ data = np.random.randn(1000)
22
+ n, _ = np.histogram(data, HIST_BINS)
23
+
24
+ # %%
25
+ # To animate the histogram, we need an ``animate`` function, which generates
26
+ # a random set of numbers and updates the heights of rectangles. We utilize a
27
+ # python closure to track an instance of `.BarContainer` whose `.Rectangle`
28
+ # patches we shall update.
29
+
30
+
31
+ def prepare_animation(bar_container):
32
+
33
+ def animate(frame_number):
34
+ # simulate new data coming in
35
+ data = np.random.randn(1000)
36
+ n, _ = np.histogram(data, HIST_BINS)
37
+ for count, rect in zip(n, bar_container.patches):
38
+ rect.set_height(count)
39
+ return bar_container.patches
40
+ return animate
41
+
42
+ # %%
43
+ # Using :func:`~matplotlib.pyplot.hist` allows us to get an instance of
44
+ # `.BarContainer`, which is a collection of `.Rectangle` instances. Calling
45
+ # ``prepare_animation`` will define ``animate`` function working with supplied
46
+ # `.BarContainer`, all this is used to setup `.FuncAnimation`.
47
+
48
+ # Output generated via `matplotlib.animation.Animation.to_jshtml`.
49
+
50
+ fig, ax = plt.subplots()
51
+ _, _, bar_container = ax.hist(data, HIST_BINS, lw=1,
52
+ ec="yellow", fc="green", alpha=0.5)
53
+ ax.set_ylim(top=55) # set safe limit to ensure that all data is visible.
54
+
55
+ ani = animation.FuncAnimation(fig, prepare_animation(bar_container), 50,
56
+ repeat=False, blit=True)
57
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/animation_demo.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ================
3
+ pyplot animation
4
+ ================
5
+
6
+ Generating an animation by calling `~.pyplot.pause` between plotting commands.
7
+
8
+ The method shown here is only suitable for simple, low-performance use. For
9
+ more demanding applications, look at the :mod:`.animation` module and the
10
+ examples that use it.
11
+
12
+ Note that calling `time.sleep` instead of `~.pyplot.pause` would *not* work.
13
+
14
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
15
+ """
16
+
17
+ import matplotlib.pyplot as plt
18
+ import numpy as np
19
+
20
+ np.random.seed(19680801)
21
+ data = np.random.random((50, 50, 50))
22
+
23
+ fig, ax = plt.subplots()
24
+
25
+ for i, img in enumerate(data):
26
+ ax.clear()
27
+ ax.imshow(img)
28
+ ax.set_title(f"frame {i}")
29
+ # Note that using time.sleep does *not* work here!
30
+ plt.pause(0.1)
testbed/matplotlib__matplotlib/galleries/examples/animation/bayes_update.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ================
3
+ The Bayes update
4
+ ================
5
+
6
+ This animation displays the posterior estimate updates as it is refitted when
7
+ new data arrives.
8
+ The vertical line represents the theoretical value to which the plotted
9
+ distribution should converge.
10
+
11
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
12
+ """
13
+
14
+ import math
15
+
16
+ import matplotlib.pyplot as plt
17
+ import numpy as np
18
+
19
+ from matplotlib.animation import FuncAnimation
20
+
21
+
22
+ def beta_pdf(x, a, b):
23
+ return (x**(a-1) * (1-x)**(b-1) * math.gamma(a + b)
24
+ / (math.gamma(a) * math.gamma(b)))
25
+
26
+
27
+ class UpdateDist:
28
+ def __init__(self, ax, prob=0.5):
29
+ self.success = 0
30
+ self.prob = prob
31
+ self.line, = ax.plot([], [], 'k-')
32
+ self.x = np.linspace(0, 1, 200)
33
+ self.ax = ax
34
+
35
+ # Set up plot parameters
36
+ self.ax.set_xlim(0, 1)
37
+ self.ax.set_ylim(0, 10)
38
+ self.ax.grid(True)
39
+
40
+ # This vertical line represents the theoretical value, to
41
+ # which the plotted distribution should converge.
42
+ self.ax.axvline(prob, linestyle='--', color='black')
43
+
44
+ def __call__(self, i):
45
+ # This way the plot can continuously run and we just keep
46
+ # watching new realizations of the process
47
+ if i == 0:
48
+ self.success = 0
49
+ self.line.set_data([], [])
50
+ return self.line,
51
+
52
+ # Choose success based on exceed a threshold with a uniform pick
53
+ if np.random.rand() < self.prob:
54
+ self.success += 1
55
+ y = beta_pdf(self.x, self.success + 1, (i - self.success) + 1)
56
+ self.line.set_data(self.x, y)
57
+ return self.line,
58
+
59
+ # Fixing random state for reproducibility
60
+ np.random.seed(19680801)
61
+
62
+
63
+ fig, ax = plt.subplots()
64
+ ud = UpdateDist(ax, prob=0.7)
65
+ anim = FuncAnimation(fig, ud, frames=100, interval=100, blit=True)
66
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/double_pendulum.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===========================
3
+ The double pendulum problem
4
+ ===========================
5
+
6
+ This animation illustrates the double pendulum problem.
7
+
8
+ Double pendulum formula translated from the C code at
9
+ http://www.physics.usyd.edu.au/~wheat/dpend_html/solve_dpend.c
10
+
11
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
12
+ """
13
+
14
+ from collections import deque
15
+
16
+ import matplotlib.pyplot as plt
17
+ import numpy as np
18
+ from numpy import cos, sin
19
+
20
+ import matplotlib.animation as animation
21
+
22
+ G = 9.8 # acceleration due to gravity, in m/s^2
23
+ L1 = 1.0 # length of pendulum 1 in m
24
+ L2 = 1.0 # length of pendulum 2 in m
25
+ L = L1 + L2 # maximal length of the combined pendulum
26
+ M1 = 1.0 # mass of pendulum 1 in kg
27
+ M2 = 1.0 # mass of pendulum 2 in kg
28
+ t_stop = 2.5 # how many seconds to simulate
29
+ history_len = 500 # how many trajectory points to display
30
+
31
+
32
+ def derivs(t, state):
33
+ dydx = np.zeros_like(state)
34
+
35
+ dydx[0] = state[1]
36
+
37
+ delta = state[2] - state[0]
38
+ den1 = (M1+M2) * L1 - M2 * L1 * cos(delta) * cos(delta)
39
+ dydx[1] = ((M2 * L1 * state[1] * state[1] * sin(delta) * cos(delta)
40
+ + M2 * G * sin(state[2]) * cos(delta)
41
+ + M2 * L2 * state[3] * state[3] * sin(delta)
42
+ - (M1+M2) * G * sin(state[0]))
43
+ / den1)
44
+
45
+ dydx[2] = state[3]
46
+
47
+ den2 = (L2/L1) * den1
48
+ dydx[3] = ((- M2 * L2 * state[3] * state[3] * sin(delta) * cos(delta)
49
+ + (M1+M2) * G * sin(state[0]) * cos(delta)
50
+ - (M1+M2) * L1 * state[1] * state[1] * sin(delta)
51
+ - (M1+M2) * G * sin(state[2]))
52
+ / den2)
53
+
54
+ return dydx
55
+
56
+ # create a time array from 0..t_stop sampled at 0.02 second steps
57
+ dt = 0.01
58
+ t = np.arange(0, t_stop, dt)
59
+
60
+ # th1 and th2 are the initial angles (degrees)
61
+ # w10 and w20 are the initial angular velocities (degrees per second)
62
+ th1 = 120.0
63
+ w1 = 0.0
64
+ th2 = -10.0
65
+ w2 = 0.0
66
+
67
+ # initial state
68
+ state = np.radians([th1, w1, th2, w2])
69
+
70
+ # integrate the ODE using Euler's method
71
+ y = np.empty((len(t), 4))
72
+ y[0] = state
73
+ for i in range(1, len(t)):
74
+ y[i] = y[i - 1] + derivs(t[i - 1], y[i - 1]) * dt
75
+
76
+ # A more accurate estimate could be obtained e.g. using scipy:
77
+ #
78
+ # y = scipy.integrate.solve_ivp(derivs, t[[0, -1]], state, t_eval=t).y.T
79
+
80
+ x1 = L1*sin(y[:, 0])
81
+ y1 = -L1*cos(y[:, 0])
82
+
83
+ x2 = L2*sin(y[:, 2]) + x1
84
+ y2 = -L2*cos(y[:, 2]) + y1
85
+
86
+ fig = plt.figure(figsize=(5, 4))
87
+ ax = fig.add_subplot(autoscale_on=False, xlim=(-L, L), ylim=(-L, 1.))
88
+ ax.set_aspect('equal')
89
+ ax.grid()
90
+
91
+ line, = ax.plot([], [], 'o-', lw=2)
92
+ trace, = ax.plot([], [], '.-', lw=1, ms=2)
93
+ time_template = 'time = %.1fs'
94
+ time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)
95
+ history_x, history_y = deque(maxlen=history_len), deque(maxlen=history_len)
96
+
97
+
98
+ def animate(i):
99
+ thisx = [0, x1[i], x2[i]]
100
+ thisy = [0, y1[i], y2[i]]
101
+
102
+ if i == 0:
103
+ history_x.clear()
104
+ history_y.clear()
105
+
106
+ history_x.appendleft(thisx[2])
107
+ history_y.appendleft(thisy[2])
108
+
109
+ line.set_data(thisx, thisy)
110
+ trace.set_data(history_x, history_y)
111
+ time_text.set_text(time_template % (i*dt))
112
+ return line, trace, time_text
113
+
114
+
115
+ ani = animation.FuncAnimation(
116
+ fig, animate, len(y), interval=dt*1000, blit=True)
117
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/dynamic_image.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =================================================
3
+ Animated image using a precomputed list of images
4
+ =================================================
5
+
6
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+ import numpy as np
11
+
12
+ import matplotlib.animation as animation
13
+
14
+ fig, ax = plt.subplots()
15
+
16
+
17
+ def f(x, y):
18
+ return np.sin(x) + np.cos(y)
19
+
20
+ x = np.linspace(0, 2 * np.pi, 120)
21
+ y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
22
+
23
+ # ims is a list of lists, each row is a list of artists to draw in the
24
+ # current frame; here we are just animating one artist, the image, in
25
+ # each frame
26
+ ims = []
27
+ for i in range(60):
28
+ x += np.pi / 15
29
+ y += np.pi / 30
30
+ im = ax.imshow(f(x, y), animated=True)
31
+ if i == 0:
32
+ ax.imshow(f(x, y)) # show an initial one first
33
+ ims.append([im])
34
+
35
+ ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
36
+ repeat_delay=1000)
37
+
38
+ # To save the animation, use e.g.
39
+ #
40
+ # ani.save("movie.mp4")
41
+ #
42
+ # or
43
+ #
44
+ # writer = animation.FFMpegWriter(
45
+ # fps=15, metadata=dict(artist='Me'), bitrate=1800)
46
+ # ani.save("movie.mp4", writer=writer)
47
+
48
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/frame_grabbing_sgskip.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==============
3
+ Frame grabbing
4
+ ==============
5
+
6
+ Use a MovieWriter directly to grab individual frames and write them to a
7
+ file. This avoids any event loop integration, and thus works even with the Agg
8
+ backend. This is not recommended for use in an interactive setting.
9
+
10
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
11
+ """
12
+
13
+ import numpy as np
14
+
15
+ import matplotlib
16
+
17
+ matplotlib.use("Agg")
18
+ import matplotlib.pyplot as plt
19
+
20
+ from matplotlib.animation import FFMpegWriter
21
+
22
+ # Fixing random state for reproducibility
23
+ np.random.seed(19680801)
24
+
25
+
26
+ metadata = dict(title='Movie Test', artist='Matplotlib',
27
+ comment='Movie support!')
28
+ writer = FFMpegWriter(fps=15, metadata=metadata)
29
+
30
+ fig = plt.figure()
31
+ l, = plt.plot([], [], 'k-o')
32
+
33
+ plt.xlim(-5, 5)
34
+ plt.ylim(-5, 5)
35
+
36
+ x0, y0 = 0, 0
37
+
38
+ with writer.saving(fig, "writer_test.mp4", 100):
39
+ for i in range(100):
40
+ x0 += 0.1 * np.random.randn()
41
+ y0 += 0.1 * np.random.randn()
42
+ l.set_data(x0, y0)
43
+ writer.grab_frame()
testbed/matplotlib__matplotlib/galleries/examples/animation/multiple_axes.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =======================
3
+ Multiple axes animation
4
+ =======================
5
+
6
+ This example showcases:
7
+
8
+ - how animation across multiple subplots works,
9
+ - using a figure artist in the animation.
10
+
11
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
12
+ """
13
+
14
+ import matplotlib.pyplot as plt
15
+ import numpy as np
16
+
17
+ import matplotlib.animation as animation
18
+ from matplotlib.patches import ConnectionPatch
19
+
20
+ fig, (axl, axr) = plt.subplots(
21
+ ncols=2,
22
+ sharey=True,
23
+ figsize=(6, 2),
24
+ gridspec_kw=dict(width_ratios=[1, 3], wspace=0),
25
+ )
26
+ axl.set_aspect(1)
27
+ axr.set_box_aspect(1 / 3)
28
+ axr.yaxis.set_visible(False)
29
+ axr.xaxis.set_ticks([0, np.pi, 2 * np.pi], ["0", r"$\pi$", r"$2\pi$"])
30
+
31
+ # draw circle with initial point in left Axes
32
+ x = np.linspace(0, 2 * np.pi, 50)
33
+ axl.plot(np.cos(x), np.sin(x), "k", lw=0.3)
34
+ point, = axl.plot(0, 0, "o")
35
+
36
+ # draw full curve to set view limits in right Axes
37
+ sine, = axr.plot(x, np.sin(x))
38
+
39
+ # draw connecting line between both graphs
40
+ con = ConnectionPatch(
41
+ (1, 0),
42
+ (0, 0),
43
+ "data",
44
+ "data",
45
+ axesA=axl,
46
+ axesB=axr,
47
+ color="C0",
48
+ ls="dotted",
49
+ )
50
+ fig.add_artist(con)
51
+
52
+
53
+ def animate(i):
54
+ x = np.linspace(0, i, int(i * 25 / np.pi))
55
+ sine.set_data(x, np.sin(x))
56
+ x, y = np.cos(i), np.sin(i)
57
+ point.set_data([x], [y])
58
+ con.xy1 = x, y
59
+ con.xy2 = i, y
60
+ return point, sine, con
61
+
62
+
63
+ ani = animation.FuncAnimation(
64
+ fig,
65
+ animate,
66
+ interval=50,
67
+ blit=False, # blitting can't be used with Figure artists
68
+ frames=x,
69
+ repeat_delay=100,
70
+ )
71
+
72
+ plt.show()
73
+
74
+ # %%
75
+ #
76
+ # .. admonition:: References
77
+ #
78
+ # The use of the following functions, methods, classes and modules is shown
79
+ # in this example:
80
+ #
81
+ # - `matplotlib.patches.ConnectionPatch`
82
+ # - `matplotlib.animation.FuncAnimation`
testbed/matplotlib__matplotlib/galleries/examples/animation/pause_resume.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =================================
3
+ Pausing and Resuming an Animation
4
+ =================================
5
+
6
+ This example showcases:
7
+
8
+ - using the Animation.pause() method to pause an animation.
9
+ - using the Animation.resume() method to resume an animation.
10
+
11
+ .. note::
12
+ This example exercises the interactive capabilities of Matplotlib, and this
13
+ will not appear in the static documentation. Please run this code on your
14
+ machine to see the interactivity.
15
+
16
+ You can copy and paste individual parts, or download the entire example
17
+ using the link at the bottom of the page.
18
+
19
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
20
+ """
21
+
22
+ import matplotlib.pyplot as plt
23
+ import numpy as np
24
+
25
+ import matplotlib.animation as animation
26
+
27
+
28
+ class PauseAnimation:
29
+ def __init__(self):
30
+ fig, ax = plt.subplots()
31
+ ax.set_title('Click to pause/resume the animation')
32
+ x = np.linspace(-0.1, 0.1, 1000)
33
+
34
+ # Start with a normal distribution
35
+ self.n0 = (1.0 / ((4 * np.pi * 2e-4 * 0.1) ** 0.5)
36
+ * np.exp(-x ** 2 / (4 * 2e-4 * 0.1)))
37
+ self.p, = ax.plot(x, self.n0)
38
+
39
+ self.animation = animation.FuncAnimation(
40
+ fig, self.update, frames=200, interval=50, blit=True)
41
+ self.paused = False
42
+
43
+ fig.canvas.mpl_connect('button_press_event', self.toggle_pause)
44
+
45
+ def toggle_pause(self, *args, **kwargs):
46
+ if self.paused:
47
+ self.animation.resume()
48
+ else:
49
+ self.animation.pause()
50
+ self.paused = not self.paused
51
+
52
+ def update(self, i):
53
+ self.n0 += i / 100 % 5
54
+ self.p.set_ydata(self.n0 % 20)
55
+ return (self.p,)
56
+
57
+
58
+ pa = PauseAnimation()
59
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/rain.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===============
3
+ Rain simulation
4
+ ===============
5
+
6
+ Simulates rain drops on a surface by animating the scale and opacity
7
+ of 50 scatter points.
8
+
9
+ Author: Nicolas P. Rougier
10
+
11
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
12
+ """
13
+
14
+ import matplotlib.pyplot as plt
15
+ import numpy as np
16
+
17
+ from matplotlib.animation import FuncAnimation
18
+
19
+ # Fixing random state for reproducibility
20
+ np.random.seed(19680801)
21
+
22
+
23
+ # Create new Figure and an Axes which fills it.
24
+ fig = plt.figure(figsize=(7, 7))
25
+ ax = fig.add_axes([0, 0, 1, 1], frameon=False)
26
+ ax.set_xlim(0, 1), ax.set_xticks([])
27
+ ax.set_ylim(0, 1), ax.set_yticks([])
28
+
29
+ # Create rain data
30
+ n_drops = 50
31
+ rain_drops = np.zeros(n_drops, dtype=[('position', float, (2,)),
32
+ ('size', float),
33
+ ('growth', float),
34
+ ('color', float, (4,))])
35
+
36
+ # Initialize the raindrops in random positions and with
37
+ # random growth rates.
38
+ rain_drops['position'] = np.random.uniform(0, 1, (n_drops, 2))
39
+ rain_drops['growth'] = np.random.uniform(50, 200, n_drops)
40
+
41
+ # Construct the scatter which we will update during animation
42
+ # as the raindrops develop.
43
+ scat = ax.scatter(rain_drops['position'][:, 0], rain_drops['position'][:, 1],
44
+ s=rain_drops['size'], lw=0.5, edgecolors=rain_drops['color'],
45
+ facecolors='none')
46
+
47
+
48
+ def update(frame_number):
49
+ # Get an index which we can use to re-spawn the oldest raindrop.
50
+ current_index = frame_number % n_drops
51
+
52
+ # Make all colors more transparent as time progresses.
53
+ rain_drops['color'][:, 3] -= 1.0/len(rain_drops)
54
+ rain_drops['color'][:, 3] = np.clip(rain_drops['color'][:, 3], 0, 1)
55
+
56
+ # Make all circles bigger.
57
+ rain_drops['size'] += rain_drops['growth']
58
+
59
+ # Pick a new position for oldest rain drop, resetting its size,
60
+ # color and growth factor.
61
+ rain_drops['position'][current_index] = np.random.uniform(0, 1, 2)
62
+ rain_drops['size'][current_index] = 5
63
+ rain_drops['color'][current_index] = (0, 0, 0, 1)
64
+ rain_drops['growth'][current_index] = np.random.uniform(50, 200)
65
+
66
+ # Update the scatter collection, with the new colors, sizes and positions.
67
+ scat.set_edgecolors(rain_drops['color'])
68
+ scat.set_sizes(rain_drops['size'])
69
+ scat.set_offsets(rain_drops['position'])
70
+
71
+
72
+ # Construct the animation, using the update function as the animation director.
73
+ animation = FuncAnimation(fig, update, interval=10, save_count=100)
74
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/random_walk.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =======================
3
+ Animated 3D random walk
4
+ =======================
5
+
6
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+ import numpy as np
11
+
12
+ import matplotlib.animation as animation
13
+
14
+ # Fixing random state for reproducibility
15
+ np.random.seed(19680801)
16
+
17
+
18
+ def random_walk(num_steps, max_step=0.05):
19
+ """Return a 3D random walk as (num_steps, 3) array."""
20
+ start_pos = np.random.random(3)
21
+ steps = np.random.uniform(-max_step, max_step, size=(num_steps, 3))
22
+ walk = start_pos + np.cumsum(steps, axis=0)
23
+ return walk
24
+
25
+
26
+ def update_lines(num, walks, lines):
27
+ for line, walk in zip(lines, walks):
28
+ # NOTE: there is no .set_data() for 3 dim data...
29
+ line.set_data(walk[:num, :2].T)
30
+ line.set_3d_properties(walk[:num, 2])
31
+ return lines
32
+
33
+
34
+ # Data: 40 random walks as (num_steps, 3) arrays
35
+ num_steps = 30
36
+ walks = [random_walk(num_steps) for index in range(40)]
37
+
38
+ # Attaching 3D axis to the figure
39
+ fig = plt.figure()
40
+ ax = fig.add_subplot(projection="3d")
41
+
42
+ # Create lines initially without data
43
+ lines = [ax.plot([], [], [])[0] for _ in walks]
44
+
45
+ # Setting the axes properties
46
+ ax.set(xlim3d=(0, 1), xlabel='X')
47
+ ax.set(ylim3d=(0, 1), ylabel='Y')
48
+ ax.set(zlim3d=(0, 1), zlabel='Z')
49
+
50
+ # Creating the Animation object
51
+ ani = animation.FuncAnimation(
52
+ fig, update_lines, num_steps, fargs=(walks, lines), interval=100)
53
+
54
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/simple_anim.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================
3
+ Animated line plot
4
+ ==================
5
+
6
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+ import numpy as np
11
+
12
+ import matplotlib.animation as animation
13
+
14
+ fig, ax = plt.subplots()
15
+
16
+ x = np.arange(0, 2*np.pi, 0.01)
17
+ line, = ax.plot(x, np.sin(x))
18
+
19
+
20
+ def animate(i):
21
+ line.set_ydata(np.sin(x + i / 50)) # update the data.
22
+ return line,
23
+
24
+
25
+ ani = animation.FuncAnimation(
26
+ fig, animate, interval=20, blit=True, save_count=50)
27
+
28
+ # To save the animation, use e.g.
29
+ #
30
+ # ani.save("movie.mp4")
31
+ #
32
+ # or
33
+ #
34
+ # writer = animation.FFMpegWriter(
35
+ # fps=15, metadata=dict(artist='Me'), bitrate=1800)
36
+ # ani.save("movie.mp4", writer=writer)
37
+
38
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/simple_scatter.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =============================
3
+ Animated scatter saved as GIF
4
+ =============================
5
+
6
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
7
+ """
8
+ import matplotlib.pyplot as plt
9
+ import numpy as np
10
+
11
+ import matplotlib.animation as animation
12
+
13
+ fig, ax = plt.subplots()
14
+ ax.set_xlim([0, 10])
15
+
16
+ scat = ax.scatter(1, 0)
17
+ x = np.linspace(0, 10)
18
+
19
+
20
+ def animate(i):
21
+ scat.set_offsets((x[i], 0))
22
+ return scat,
23
+
24
+ ani = animation.FuncAnimation(fig, animate, repeat=True,
25
+ frames=len(x) - 1, interval=50)
26
+
27
+ # To save the animation using Pillow as a gif
28
+ # writer = animation.PillowWriter(fps=15,
29
+ # metadata=dict(artist='Me'),
30
+ # bitrate=1800)
31
+ # ani.save('scatter.gif', writer=writer)
32
+
33
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/strip_chart.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ============
3
+ Oscilloscope
4
+ ============
5
+
6
+ Emulates an oscilloscope.
7
+
8
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
9
+ """
10
+
11
+ import matplotlib.pyplot as plt
12
+ import numpy as np
13
+
14
+ import matplotlib.animation as animation
15
+ from matplotlib.lines import Line2D
16
+
17
+
18
+ class Scope:
19
+ def __init__(self, ax, maxt=2, dt=0.02):
20
+ self.ax = ax
21
+ self.dt = dt
22
+ self.maxt = maxt
23
+ self.tdata = [0]
24
+ self.ydata = [0]
25
+ self.line = Line2D(self.tdata, self.ydata)
26
+ self.ax.add_line(self.line)
27
+ self.ax.set_ylim(-.1, 1.1)
28
+ self.ax.set_xlim(0, self.maxt)
29
+
30
+ def update(self, y):
31
+ lastt = self.tdata[-1]
32
+ if lastt >= self.tdata[0] + self.maxt: # reset the arrays
33
+ self.tdata = [self.tdata[-1]]
34
+ self.ydata = [self.ydata[-1]]
35
+ self.ax.set_xlim(self.tdata[0], self.tdata[0] + self.maxt)
36
+ self.ax.figure.canvas.draw()
37
+
38
+ # This slightly more complex calculation avoids floating-point issues
39
+ # from just repeatedly adding `self.dt` to the previous value.
40
+ t = self.tdata[0] + len(self.tdata) * self.dt
41
+
42
+ self.tdata.append(t)
43
+ self.ydata.append(y)
44
+ self.line.set_data(self.tdata, self.ydata)
45
+ return self.line,
46
+
47
+
48
+ def emitter(p=0.1):
49
+ """Return a random value in [0, 1) with probability p, else 0."""
50
+ while True:
51
+ v = np.random.rand()
52
+ if v > p:
53
+ yield 0.
54
+ else:
55
+ yield np.random.rand()
56
+
57
+
58
+ # Fixing random state for reproducibility
59
+ np.random.seed(19680801 // 10)
60
+
61
+
62
+ fig, ax = plt.subplots()
63
+ scope = Scope(ax)
64
+
65
+ # pass a generator in "emitter" to produce data for the update func
66
+ ani = animation.FuncAnimation(fig, scope.update, emitter, interval=50,
67
+ blit=True, save_count=100)
68
+
69
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/animation/unchained.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ========================
3
+ MATPLOTLIB **UNCHAINED**
4
+ ========================
5
+
6
+ Comparative path demonstration of frequency from a fake signal of a pulsar
7
+ (mostly known because of the cover for Joy Division's Unknown Pleasures).
8
+
9
+ Author: Nicolas P. Rougier
10
+
11
+ Output generated via `matplotlib.animation.Animation.to_jshtml`.
12
+ """
13
+
14
+ import matplotlib.pyplot as plt
15
+ import numpy as np
16
+
17
+ import matplotlib.animation as animation
18
+
19
+ # Fixing random state for reproducibility
20
+ np.random.seed(19680801)
21
+
22
+
23
+ # Create new Figure with black background
24
+ fig = plt.figure(figsize=(8, 8), facecolor='black')
25
+
26
+ # Add a subplot with no frame
27
+ ax = plt.subplot(frameon=False)
28
+
29
+ # Generate random data
30
+ data = np.random.uniform(0, 1, (64, 75))
31
+ X = np.linspace(-1, 1, data.shape[-1])
32
+ G = 1.5 * np.exp(-4 * X ** 2)
33
+
34
+ # Generate line plots
35
+ lines = []
36
+ for i in range(len(data)):
37
+ # Small reduction of the X extents to get a cheap perspective effect
38
+ xscale = 1 - i / 200.
39
+ # Same for linewidth (thicker strokes on bottom)
40
+ lw = 1.5 - i / 100.0
41
+ line, = ax.plot(xscale * X, i + G * data[i], color="w", lw=lw)
42
+ lines.append(line)
43
+
44
+ # Set y limit (or first line is cropped because of thickness)
45
+ ax.set_ylim(-1, 70)
46
+
47
+ # No ticks
48
+ ax.set_xticks([])
49
+ ax.set_yticks([])
50
+
51
+ # 2 part titles to get different font weights
52
+ ax.text(0.5, 1.0, "MATPLOTLIB ", transform=ax.transAxes,
53
+ ha="right", va="bottom", color="w",
54
+ family="sans-serif", fontweight="light", fontsize=16)
55
+ ax.text(0.5, 1.0, "UNCHAINED", transform=ax.transAxes,
56
+ ha="left", va="bottom", color="w",
57
+ family="sans-serif", fontweight="bold", fontsize=16)
58
+
59
+
60
+ def update(*args):
61
+ # Shift all data to the right
62
+ data[:, 1:] = data[:, :-1]
63
+
64
+ # Fill-in new values
65
+ data[:, 0] = np.random.uniform(0, 1, len(data))
66
+
67
+ # Update data
68
+ for i in range(len(data)):
69
+ lines[i].set_ydata(i + G * data[i])
70
+
71
+ # Return modified artists
72
+ return lines
73
+
74
+ # Construct the animation, using the update function as the animation director.
75
+ anim = animation.FuncAnimation(fig, update, interval=10, save_count=100)
76
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/README.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ .. _axes_grid_examples:
2
+
3
+ .. _axes_grid1-examples-index:
4
+
5
+ Module - axes_grid1
6
+ ===================
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_anchored_direction_arrows.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ========================
3
+ Anchored Direction Arrow
4
+ ========================
5
+
6
+ """
7
+ import matplotlib.pyplot as plt
8
+ import numpy as np
9
+
10
+ import matplotlib.font_manager as fm
11
+ from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDirectionArrows
12
+
13
+ # Fixing random state for reproducibility
14
+ np.random.seed(19680801)
15
+
16
+ fig, ax = plt.subplots()
17
+ ax.imshow(np.random.random((10, 10)))
18
+
19
+ # Simple example
20
+ simple_arrow = AnchoredDirectionArrows(ax.transAxes, 'X', 'Y')
21
+ ax.add_artist(simple_arrow)
22
+
23
+ # High contrast arrow
24
+ high_contrast_part_1 = AnchoredDirectionArrows(
25
+ ax.transAxes,
26
+ '111', r'11$\overline{2}$',
27
+ loc='upper right',
28
+ arrow_props={'ec': 'w', 'fc': 'none', 'alpha': 1,
29
+ 'lw': 2}
30
+ )
31
+ ax.add_artist(high_contrast_part_1)
32
+
33
+ high_contrast_part_2 = AnchoredDirectionArrows(
34
+ ax.transAxes,
35
+ '111', r'11$\overline{2}$',
36
+ loc='upper right',
37
+ arrow_props={'ec': 'none', 'fc': 'k'},
38
+ text_props={'ec': 'w', 'fc': 'k', 'lw': 0.4}
39
+ )
40
+ ax.add_artist(high_contrast_part_2)
41
+
42
+ # Rotated arrow
43
+ fontprops = fm.FontProperties(family='serif')
44
+
45
+ rotated_arrow = AnchoredDirectionArrows(
46
+ ax.transAxes,
47
+ '30', '120',
48
+ loc='center',
49
+ color='w',
50
+ angle=30,
51
+ fontproperties=fontprops
52
+ )
53
+ ax.add_artist(rotated_arrow)
54
+
55
+ # Altering arrow directions
56
+ a1 = AnchoredDirectionArrows(
57
+ ax.transAxes, 'A', 'B', loc='lower center',
58
+ length=-0.15,
59
+ sep_x=0.03, sep_y=0.03,
60
+ color='r'
61
+ )
62
+ ax.add_artist(a1)
63
+
64
+ a2 = AnchoredDirectionArrows(
65
+ ax.transAxes, 'A', ' B', loc='lower left',
66
+ aspect_ratio=-1,
67
+ sep_x=0.01, sep_y=-0.02,
68
+ color='orange'
69
+ )
70
+ ax.add_artist(a2)
71
+
72
+
73
+ a3 = AnchoredDirectionArrows(
74
+ ax.transAxes, ' A', 'B', loc='lower right',
75
+ length=-0.15,
76
+ aspect_ratio=-1,
77
+ sep_y=-0.1, sep_x=0.04,
78
+ color='cyan'
79
+ )
80
+ ax.add_artist(a3)
81
+
82
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_divider.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ============
3
+ Axes divider
4
+ ============
5
+
6
+ Axes divider to calculate location of axes and
7
+ create a divider for them using existing axes instances.
8
+ """
9
+
10
+ import matplotlib.pyplot as plt
11
+
12
+ from matplotlib import cbook
13
+
14
+
15
+ def get_demo_image():
16
+ z = cbook.get_sample_data("axes_grid/bivariate_normal.npy") # 15x15 array
17
+ return z, (-3, 4, -4, 3)
18
+
19
+
20
+ def demo_simple_image(ax):
21
+ Z, extent = get_demo_image()
22
+
23
+ im = ax.imshow(Z, extent=extent)
24
+ cb = plt.colorbar(im)
25
+ cb.ax.yaxis.set_tick_params(labelright=False)
26
+
27
+
28
+ def demo_locatable_axes_hard(fig):
29
+ from mpl_toolkits.axes_grid1 import Size, SubplotDivider
30
+
31
+ divider = SubplotDivider(fig, 2, 2, 2, aspect=True)
32
+
33
+ # axes for image
34
+ ax = fig.add_subplot(axes_locator=divider.new_locator(nx=0, ny=0))
35
+ # axes for colorbar
36
+ ax_cb = fig.add_subplot(axes_locator=divider.new_locator(nx=2, ny=0))
37
+
38
+ divider.set_horizontal([
39
+ Size.AxesX(ax), # main axes
40
+ Size.Fixed(0.05), # padding, 0.1 inch
41
+ Size.Fixed(0.2), # colorbar, 0.3 inch
42
+ ])
43
+ divider.set_vertical([Size.AxesY(ax)])
44
+
45
+ Z, extent = get_demo_image()
46
+
47
+ im = ax.imshow(Z, extent=extent)
48
+ plt.colorbar(im, cax=ax_cb)
49
+ ax_cb.yaxis.set_tick_params(labelright=False)
50
+
51
+
52
+ def demo_locatable_axes_easy(ax):
53
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
54
+
55
+ divider = make_axes_locatable(ax)
56
+
57
+ ax_cb = divider.append_axes("right", size="5%", pad=0.05)
58
+ fig = ax.get_figure()
59
+ fig.add_axes(ax_cb)
60
+
61
+ Z, extent = get_demo_image()
62
+ im = ax.imshow(Z, extent=extent)
63
+
64
+ plt.colorbar(im, cax=ax_cb)
65
+ ax_cb.yaxis.tick_right()
66
+ ax_cb.yaxis.set_tick_params(labelright=False)
67
+
68
+
69
+ def demo_images_side_by_side(ax):
70
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
71
+
72
+ divider = make_axes_locatable(ax)
73
+
74
+ Z, extent = get_demo_image()
75
+ ax2 = divider.append_axes("right", size="100%", pad=0.05)
76
+ fig1 = ax.get_figure()
77
+ fig1.add_axes(ax2)
78
+
79
+ ax.imshow(Z, extent=extent)
80
+ ax2.imshow(Z, extent=extent)
81
+ ax2.yaxis.set_tick_params(labelleft=False)
82
+
83
+
84
+ def demo():
85
+ fig = plt.figure(figsize=(6, 6))
86
+
87
+ # PLOT 1
88
+ # simple image & colorbar
89
+ ax = fig.add_subplot(2, 2, 1)
90
+ demo_simple_image(ax)
91
+
92
+ # PLOT 2
93
+ # image and colorbar with draw-time positioning -- a hard way
94
+ demo_locatable_axes_hard(fig)
95
+
96
+ # PLOT 3
97
+ # image and colorbar with draw-time positioning -- an easy way
98
+ ax = fig.add_subplot(2, 2, 3)
99
+ demo_locatable_axes_easy(ax)
100
+
101
+ # PLOT 4
102
+ # two images side by side with fixed padding.
103
+ ax = fig.add_subplot(2, 2, 4)
104
+ demo_images_side_by_side(ax)
105
+
106
+ plt.show()
107
+
108
+
109
+ demo()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_grid.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==============
3
+ Demo Axes Grid
4
+ ==============
5
+
6
+ Grid of 2x2 images with a single colorbar or with one colorbar per axes.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+
11
+ from matplotlib import cbook
12
+ from mpl_toolkits.axes_grid1 import ImageGrid
13
+
14
+ fig = plt.figure(figsize=(10.5, 2.5))
15
+ Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy") # 15x15 array
16
+ extent = (-3, 4, -4, 3)
17
+
18
+
19
+ # A grid of 2x2 images with 0.05 inch pad between images and only the
20
+ # lower-left axes is labeled.
21
+ grid = ImageGrid(
22
+ fig, 141, # similar to fig.add_subplot(141).
23
+ nrows_ncols=(2, 2), axes_pad=0.05, label_mode="1")
24
+ for ax in grid:
25
+ ax.imshow(Z, extent=extent)
26
+ # This only affects axes in first column and second row as share_all=False.
27
+ grid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])
28
+
29
+
30
+ # A grid of 2x2 images with a single colorbar.
31
+ grid = ImageGrid(
32
+ fig, 142, # similar to fig.add_subplot(142).
33
+ nrows_ncols=(2, 2), axes_pad=0.0, label_mode="L", share_all=True,
34
+ cbar_location="top", cbar_mode="single")
35
+ for ax in grid:
36
+ im = ax.imshow(Z, extent=extent)
37
+ grid.cbar_axes[0].colorbar(im)
38
+ for cax in grid.cbar_axes:
39
+ cax.tick_params(labeltop=False)
40
+ # This affects all axes as share_all = True.
41
+ grid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])
42
+
43
+
44
+ # A grid of 2x2 images. Each image has its own colorbar.
45
+ grid = ImageGrid(
46
+ fig, 143, # similar to fig.add_subplot(143).
47
+ nrows_ncols=(2, 2), axes_pad=0.1, label_mode="1", share_all=True,
48
+ cbar_location="top", cbar_mode="each", cbar_size="7%", cbar_pad="2%")
49
+ for ax, cax in zip(grid, grid.cbar_axes):
50
+ im = ax.imshow(Z, extent=extent)
51
+ cax.colorbar(im)
52
+ cax.tick_params(labeltop=False)
53
+ # This affects all axes as share_all = True.
54
+ grid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])
55
+
56
+
57
+ # A grid of 2x2 images. Each image has its own colorbar.
58
+ grid = ImageGrid(
59
+ fig, 144, # similar to fig.add_subplot(144).
60
+ nrows_ncols=(2, 2), axes_pad=(0.45, 0.15), label_mode="1", share_all=True,
61
+ cbar_location="right", cbar_mode="each", cbar_size="7%", cbar_pad="2%")
62
+ # Use a different colorbar range every time
63
+ limits = ((0, 1), (-2, 2), (-1.7, 1.4), (-1.5, 1))
64
+ for ax, cax, vlim in zip(grid, grid.cbar_axes, limits):
65
+ im = ax.imshow(Z, extent=extent, vmin=vlim[0], vmax=vlim[1])
66
+ cb = cax.colorbar(im)
67
+ cb.set_ticks((vlim[0], vlim[1]))
68
+ # This affects all axes as share_all = True.
69
+ grid.axes_llc.set(xticks=[-2, 0, 2], yticks=[-2, 0, 2])
70
+
71
+
72
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_grid2.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==========
3
+ Axes Grid2
4
+ ==========
5
+
6
+ Grid of images with shared xaxis and yaxis.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+ import numpy as np
11
+
12
+ from matplotlib import cbook
13
+ from mpl_toolkits.axes_grid1 import ImageGrid
14
+
15
+
16
+ def add_inner_title(ax, title, loc, **kwargs):
17
+ from matplotlib.offsetbox import AnchoredText
18
+ from matplotlib.patheffects import withStroke
19
+ prop = dict(path_effects=[withStroke(foreground='w', linewidth=3)],
20
+ size=plt.rcParams['legend.fontsize'])
21
+ at = AnchoredText(title, loc=loc, prop=prop,
22
+ pad=0., borderpad=0.5,
23
+ frameon=False, **kwargs)
24
+ ax.add_artist(at)
25
+ return at
26
+
27
+
28
+ fig = plt.figure(figsize=(6, 6))
29
+
30
+ # Prepare images
31
+ Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy")
32
+ extent = (-3, 4, -4, 3)
33
+ ZS = [Z[i::3, :] for i in range(3)]
34
+ extent = extent[0], extent[1]/3., extent[2], extent[3]
35
+
36
+ # *** Demo 1: colorbar at each axes ***
37
+ grid = ImageGrid(
38
+ # 211 = at the position of fig.add_subplot(211)
39
+ fig, 211, nrows_ncols=(1, 3), axes_pad=0.05, label_mode="1", share_all=True,
40
+ cbar_location="top", cbar_mode="each", cbar_size="7%", cbar_pad="1%")
41
+ grid[0].set(xticks=[-2, 0], yticks=[-2, 0, 2])
42
+
43
+ for i, (ax, z) in enumerate(zip(grid, ZS)):
44
+ im = ax.imshow(z, origin="lower", extent=extent)
45
+ cb = ax.cax.colorbar(im)
46
+ # Changing the colorbar ticks
47
+ if i in [1, 2]:
48
+ cb.set_ticks([-1, 0, 1])
49
+
50
+ for ax, im_title in zip(grid, ["Image 1", "Image 2", "Image 3"]):
51
+ add_inner_title(ax, im_title, loc='lower left')
52
+
53
+ # *** Demo 2: shared colorbar ***
54
+ grid2 = ImageGrid(
55
+ fig, 212, nrows_ncols=(1, 3), axes_pad=0.05, label_mode="1", share_all=True,
56
+ cbar_location="right", cbar_mode="single", cbar_size="10%", cbar_pad=0.05)
57
+ grid2[0].set(xlabel="X", ylabel="Y", xticks=[-2, 0], yticks=[-2, 0, 2])
58
+
59
+ clim = (np.min(ZS), np.max(ZS))
60
+ for ax, z in zip(grid2, ZS):
61
+ im = ax.imshow(z, clim=clim, origin="lower", extent=extent)
62
+
63
+ # With cbar_mode="single", cax attribute of all axes are identical.
64
+ ax.cax.colorbar(im)
65
+
66
+ for ax, im_title in zip(grid2, ["(a)", "(b)", "(c)"]):
67
+ add_inner_title(ax, im_title, loc='upper left')
68
+
69
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_hbox_divider.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ================================
3
+ HBoxDivider and VBoxDivider demo
4
+ ================================
5
+
6
+ Using an `.HBoxDivider` to arrange subplots.
7
+
8
+ Note that both axes' location are adjusted so that they have
9
+ equal heights while maintaining their aspect ratios.
10
+
11
+ """
12
+
13
+ import matplotlib.pyplot as plt
14
+ import numpy as np
15
+
16
+ from mpl_toolkits.axes_grid1.axes_divider import HBoxDivider, VBoxDivider
17
+ import mpl_toolkits.axes_grid1.axes_size as Size
18
+
19
+ arr1 = np.arange(20).reshape((4, 5))
20
+ arr2 = np.arange(20).reshape((5, 4))
21
+
22
+ fig, (ax1, ax2) = plt.subplots(1, 2)
23
+ ax1.imshow(arr1)
24
+ ax2.imshow(arr2)
25
+
26
+ pad = 0.5 # pad in inches
27
+ divider = HBoxDivider(
28
+ fig, 111,
29
+ horizontal=[Size.AxesX(ax1), Size.Fixed(pad), Size.AxesX(ax2)],
30
+ vertical=[Size.AxesY(ax1), Size.Scaled(1), Size.AxesY(ax2)])
31
+ ax1.set_axes_locator(divider.new_locator(0))
32
+ ax2.set_axes_locator(divider.new_locator(2))
33
+
34
+ plt.show()
35
+
36
+ # %%
37
+ # Using a `.VBoxDivider` to arrange subplots.
38
+ #
39
+ # Note that both axes' location are adjusted so that they have
40
+ # equal widths while maintaining their aspect ratios.
41
+
42
+ fig, (ax1, ax2) = plt.subplots(2, 1)
43
+ ax1.imshow(arr1)
44
+ ax2.imshow(arr2)
45
+
46
+ divider = VBoxDivider(
47
+ fig, 111,
48
+ horizontal=[Size.AxesX(ax1), Size.Scaled(1), Size.AxesX(ax2)],
49
+ vertical=[Size.AxesY(ax1), Size.Fixed(pad), Size.AxesY(ax2)])
50
+
51
+ ax1.set_axes_locator(divider.new_locator(0))
52
+ ax2.set_axes_locator(divider.new_locator(2))
53
+
54
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_axes_rgb.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================================
3
+ Showing RGB channels using RGBAxes
4
+ ==================================
5
+
6
+ `~.axes_grid1.axes_rgb.RGBAxes` creates a layout of 4 Axes for displaying RGB
7
+ channels: one large Axes for the RGB image and 3 smaller Axes for the R, G, B
8
+ channels.
9
+ """
10
+
11
+ import matplotlib.pyplot as plt
12
+ import numpy as np
13
+
14
+ from matplotlib import cbook
15
+ from mpl_toolkits.axes_grid1.axes_rgb import RGBAxes, make_rgb_axes
16
+
17
+
18
+ def get_rgb():
19
+ Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy")
20
+ Z[Z < 0] = 0.
21
+ Z = Z / Z.max()
22
+
23
+ R = Z[:13, :13]
24
+ G = Z[2:, 2:]
25
+ B = Z[:13, 2:]
26
+
27
+ return R, G, B
28
+
29
+
30
+ def make_cube(r, g, b):
31
+ ny, nx = r.shape
32
+ R = np.zeros((ny, nx, 3))
33
+ R[:, :, 0] = r
34
+ G = np.zeros_like(R)
35
+ G[:, :, 1] = g
36
+ B = np.zeros_like(R)
37
+ B[:, :, 2] = b
38
+
39
+ RGB = R + G + B
40
+
41
+ return R, G, B, RGB
42
+
43
+
44
+ def demo_rgb1():
45
+ fig = plt.figure()
46
+ ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)
47
+ r, g, b = get_rgb()
48
+ ax.imshow_rgb(r, g, b)
49
+
50
+
51
+ def demo_rgb2():
52
+ fig, ax = plt.subplots()
53
+ ax_r, ax_g, ax_b = make_rgb_axes(ax, pad=0.02)
54
+
55
+ r, g, b = get_rgb()
56
+ im_r, im_g, im_b, im_rgb = make_cube(r, g, b)
57
+ ax.imshow(im_rgb)
58
+ ax_r.imshow(im_r)
59
+ ax_g.imshow(im_g)
60
+ ax_b.imshow(im_b)
61
+
62
+ for ax in fig.axes:
63
+ ax.tick_params(direction='in', color='w')
64
+ ax.spines[:].set_color("w")
65
+
66
+
67
+ demo_rgb1()
68
+ demo_rgb2()
69
+
70
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_colorbar_of_inset_axes.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===============================
3
+ Adding a colorbar to inset axes
4
+ ===============================
5
+ """
6
+
7
+ import matplotlib.pyplot as plt
8
+
9
+ from matplotlib import cbook
10
+ from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes
11
+
12
+ fig, ax = plt.subplots(figsize=[5, 4])
13
+ ax.set(aspect=1, xlim=(-15, 15), ylim=(-20, 5))
14
+
15
+ Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy")
16
+ extent = (-3, 4, -4, 3)
17
+
18
+ axins = zoomed_inset_axes(ax, zoom=2, loc='upper left')
19
+ axins.set(xticks=[], yticks=[])
20
+ im = axins.imshow(Z, extent=extent, origin="lower")
21
+
22
+ # colorbar
23
+ cax = inset_axes(axins,
24
+ width="5%", # width = 10% of parent_bbox width
25
+ height="100%", # height : 50%
26
+ loc='lower left',
27
+ bbox_to_anchor=(1.05, 0., 1, 1),
28
+ bbox_transform=axins.transAxes,
29
+ borderpad=0,
30
+ )
31
+ fig.colorbar(im, cax=cax)
32
+
33
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_colorbar_with_axes_divider.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =========================
3
+ Colorbar with AxesDivider
4
+ =========================
5
+
6
+ The `.axes_divider.make_axes_locatable` function takes an existing axes, adds
7
+ it to a new `.AxesDivider` and returns the `.AxesDivider`. The `.append_axes`
8
+ method of the `.AxesDivider` can then be used to create a new axes on a given
9
+ side ("top", "right", "bottom", or "left") of the original axes. This example
10
+ uses `.append_axes` to add colorbars next to axes.
11
+ """
12
+
13
+ import matplotlib.pyplot as plt
14
+
15
+ from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable
16
+
17
+ fig, (ax1, ax2) = plt.subplots(1, 2)
18
+ fig.subplots_adjust(wspace=0.5)
19
+
20
+ im1 = ax1.imshow([[1, 2], [3, 4]])
21
+ ax1_divider = make_axes_locatable(ax1)
22
+ # Add an Axes to the right of the main Axes.
23
+ cax1 = ax1_divider.append_axes("right", size="7%", pad="2%")
24
+ cb1 = fig.colorbar(im1, cax=cax1)
25
+
26
+ im2 = ax2.imshow([[1, 2], [3, 4]])
27
+ ax2_divider = make_axes_locatable(ax2)
28
+ # Add an Axes above the main Axes.
29
+ cax2 = ax2_divider.append_axes("top", size="7%", pad="2%")
30
+ cb2 = fig.colorbar(im2, cax=cax2, orientation="horizontal")
31
+ # Change tick position to top (with the default tick position "bottom", ticks
32
+ # overlap the image).
33
+ cax2.xaxis.set_ticks_position("top")
34
+
35
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_colorbar_with_inset_locator.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==============================================================
3
+ Controlling the position and size of colorbars with Inset Axes
4
+ ==============================================================
5
+
6
+ This example shows how to control the position, height, and width of
7
+ colorbars using `~mpl_toolkits.axes_grid1.inset_locator.inset_axes`.
8
+
9
+ Inset axes placement is controlled as for legends: either by providing a *loc*
10
+ option ("upper right", "best", ...), or by providing a locator with respect to
11
+ the parent bbox. Parameters such as *bbox_to_anchor* and *borderpad* likewise
12
+ work in the same way, and are also demonstrated here.
13
+ """
14
+
15
+ import matplotlib.pyplot as plt
16
+
17
+ from mpl_toolkits.axes_grid1.inset_locator import inset_axes
18
+
19
+ fig, (ax1, ax2) = plt.subplots(1, 2, figsize=[6, 3])
20
+
21
+ im1 = ax1.imshow([[1, 2], [2, 3]])
22
+ axins1 = inset_axes(
23
+ ax1,
24
+ width="50%", # width: 50% of parent_bbox width
25
+ height="5%", # height: 5%
26
+ loc="upper right",
27
+ )
28
+ axins1.xaxis.set_ticks_position("bottom")
29
+ fig.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3])
30
+
31
+ im = ax2.imshow([[1, 2], [2, 3]])
32
+ axins = inset_axes(
33
+ ax2,
34
+ width="5%", # width: 5% of parent_bbox width
35
+ height="50%", # height: 50%
36
+ loc="lower left",
37
+ bbox_to_anchor=(1.05, 0., 1, 1),
38
+ bbox_transform=ax2.transAxes,
39
+ borderpad=0,
40
+ )
41
+ fig.colorbar(im, cax=axins, ticks=[1, 2, 3])
42
+
43
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_edge_colorbar.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===============================
3
+ Per-row or per-column colorbars
4
+ ===============================
5
+
6
+ This example shows how to use one common colorbar for each row or column
7
+ of an image grid.
8
+ """
9
+
10
+ import matplotlib.pyplot as plt
11
+
12
+ from matplotlib import cbook
13
+ from mpl_toolkits.axes_grid1 import AxesGrid
14
+
15
+
16
+ def get_demo_image():
17
+ z = cbook.get_sample_data("axes_grid/bivariate_normal.npy") # 15x15 array
18
+ return z, (-3, 4, -4, 3)
19
+
20
+
21
+ def demo_bottom_cbar(fig):
22
+ """
23
+ A grid of 2x2 images with a colorbar for each column.
24
+ """
25
+ grid = AxesGrid(fig, 121, # similar to subplot(121)
26
+ nrows_ncols=(2, 2),
27
+ axes_pad=0.10,
28
+ share_all=True,
29
+ label_mode="1",
30
+ cbar_location="bottom",
31
+ cbar_mode="edge",
32
+ cbar_pad=0.25,
33
+ cbar_size="15%",
34
+ direction="column"
35
+ )
36
+
37
+ Z, extent = get_demo_image()
38
+ cmaps = ["autumn", "summer"]
39
+ for i in range(4):
40
+ im = grid[i].imshow(Z, extent=extent, cmap=cmaps[i//2])
41
+ if i % 2:
42
+ grid.cbar_axes[i//2].colorbar(im)
43
+
44
+ for cax in grid.cbar_axes:
45
+ cax.axis[cax.orientation].set_label("Bar")
46
+
47
+ # This affects all axes as share_all = True.
48
+ grid.axes_llc.set_xticks([-2, 0, 2])
49
+ grid.axes_llc.set_yticks([-2, 0, 2])
50
+
51
+
52
+ def demo_right_cbar(fig):
53
+ """
54
+ A grid of 2x2 images. Each row has its own colorbar.
55
+ """
56
+ grid = AxesGrid(fig, 122, # similar to subplot(122)
57
+ nrows_ncols=(2, 2),
58
+ axes_pad=0.10,
59
+ label_mode="1",
60
+ share_all=True,
61
+ cbar_location="right",
62
+ cbar_mode="edge",
63
+ cbar_size="7%",
64
+ cbar_pad="2%",
65
+ )
66
+ Z, extent = get_demo_image()
67
+ cmaps = ["spring", "winter"]
68
+ for i in range(4):
69
+ im = grid[i].imshow(Z, extent=extent, cmap=cmaps[i//2])
70
+ if i % 2:
71
+ grid.cbar_axes[i//2].colorbar(im)
72
+
73
+ for cax in grid.cbar_axes:
74
+ cax.axis[cax.orientation].set_label('Foo')
75
+
76
+ # This affects all axes because we set share_all = True.
77
+ grid.axes_llc.set_xticks([-2, 0, 2])
78
+ grid.axes_llc.set_yticks([-2, 0, 2])
79
+
80
+
81
+ fig = plt.figure()
82
+
83
+ demo_bottom_cbar(fig)
84
+ demo_right_cbar(fig)
85
+
86
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_fixed_size_axes.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===============================
3
+ Axes with a fixed physical size
4
+ ===============================
5
+
6
+ Note that this can be accomplished with the main library for
7
+ Axes on Figures that do not change size: :ref:`fixed_size_axes`
8
+ """
9
+
10
+ import matplotlib.pyplot as plt
11
+
12
+ from mpl_toolkits.axes_grid1 import Divider, Size
13
+
14
+ # %%
15
+
16
+
17
+ fig = plt.figure(figsize=(6, 6))
18
+
19
+ # The first items are for padding and the second items are for the axes.
20
+ # sizes are in inch.
21
+ h = [Size.Fixed(1.0), Size.Fixed(4.5)]
22
+ v = [Size.Fixed(0.7), Size.Fixed(5.)]
23
+
24
+ divider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)
25
+ # The width and height of the rectangle are ignored.
26
+
27
+ ax = fig.add_axes(divider.get_position(),
28
+ axes_locator=divider.new_locator(nx=1, ny=1))
29
+
30
+ ax.plot([1, 2, 3])
31
+
32
+ # %%
33
+
34
+
35
+ fig = plt.figure(figsize=(6, 6))
36
+
37
+ # The first & third items are for padding and the second items are for the
38
+ # axes. Sizes are in inches.
39
+ h = [Size.Fixed(1.0), Size.Scaled(1.), Size.Fixed(.2)]
40
+ v = [Size.Fixed(0.7), Size.Scaled(1.), Size.Fixed(.5)]
41
+
42
+ divider = Divider(fig, (0, 0, 1, 1), h, v, aspect=False)
43
+ # The width and height of the rectangle are ignored.
44
+
45
+ ax = fig.add_axes(divider.get_position(),
46
+ axes_locator=divider.new_locator(nx=1, ny=1))
47
+
48
+ ax.plot([1, 2, 3])
49
+
50
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/demo_imagegrid_aspect.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =========================================
3
+ Setting a fixed aspect on ImageGrid cells
4
+ =========================================
5
+ """
6
+
7
+ import matplotlib.pyplot as plt
8
+
9
+ from mpl_toolkits.axes_grid1 import ImageGrid
10
+
11
+ fig = plt.figure()
12
+
13
+ grid1 = ImageGrid(fig, 121, (2, 2), axes_pad=0.1,
14
+ aspect=True, share_all=True)
15
+ for i in [0, 1]:
16
+ grid1[i].set_aspect(2)
17
+
18
+ grid2 = ImageGrid(fig, 122, (2, 2), axes_pad=0.1,
19
+ aspect=True, share_all=True)
20
+ for i in [1, 3]:
21
+ grid2[i].set_aspect(2)
22
+
23
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/inset_locator_demo.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================
3
+ Inset locator demo
4
+ ==================
5
+
6
+ """
7
+
8
+ # %%
9
+ # The `.inset_locator`'s `~.inset_locator.inset_axes` allows
10
+ # easily placing insets in the corners of the axes by specifying a width and
11
+ # height and optionally a location (loc) that accepts locations as codes,
12
+ # similar to `~matplotlib.axes.Axes.legend`.
13
+ # By default, the inset is offset by some points from the axes,
14
+ # controlled via the *borderpad* parameter.
15
+
16
+ import matplotlib.pyplot as plt
17
+
18
+ from mpl_toolkits.axes_grid1.inset_locator import inset_axes
19
+
20
+ fig, (ax, ax2) = plt.subplots(1, 2, figsize=[5.5, 2.8])
21
+
22
+ # Create inset of width 1.3 inches and height 0.9 inches
23
+ # at the default upper right location
24
+ axins = inset_axes(ax, width=1.3, height=0.9)
25
+
26
+ # Create inset of width 30% and height 40% of the parent axes' bounding box
27
+ # at the lower left corner (loc=3)
28
+ axins2 = inset_axes(ax, width="30%", height="40%", loc=3)
29
+
30
+ # Create inset of mixed specifications in the second subplot;
31
+ # width is 30% of parent axes' bounding box and
32
+ # height is 1 inch at the upper left corner (loc=2)
33
+ axins3 = inset_axes(ax2, width="30%", height=1., loc=2)
34
+
35
+ # Create an inset in the lower right corner (loc=4) with borderpad=1, i.e.
36
+ # 10 points padding (as 10pt is the default fontsize) to the parent axes
37
+ axins4 = inset_axes(ax2, width="20%", height="20%", loc=4, borderpad=1)
38
+
39
+ # Turn ticklabels of insets off
40
+ for axi in [axins, axins2, axins3, axins4]:
41
+ axi.tick_params(labelleft=False, labelbottom=False)
42
+
43
+ plt.show()
44
+
45
+
46
+ # %%
47
+ # The parameters *bbox_to_anchor* and *bbox_transform* can be used for a more
48
+ # fine-grained control over the inset position and size or even to position
49
+ # the inset at completely arbitrary positions.
50
+ # The *bbox_to_anchor* sets the bounding box in coordinates according to the
51
+ # *bbox_transform*.
52
+ #
53
+
54
+ fig = plt.figure(figsize=[5.5, 2.8])
55
+ ax = fig.add_subplot(121)
56
+
57
+ # We use the axes transform as bbox_transform. Therefore, the bounding box
58
+ # needs to be specified in axes coordinates ((0, 0) is the lower left corner
59
+ # of the axes, (1, 1) is the upper right corner).
60
+ # The bounding box (.2, .4, .6, .5) starts at (.2, .4) and ranges to (.8, .9)
61
+ # in those coordinates.
62
+ # Inside this bounding box an inset of half the bounding box' width and
63
+ # three quarters of the bounding box' height is created. The lower left corner
64
+ # of the inset is aligned to the lower left corner of the bounding box (loc=3).
65
+ # The inset is then offset by the default 0.5 in units of the font size.
66
+
67
+ axins = inset_axes(ax, width="50%", height="75%",
68
+ bbox_to_anchor=(.2, .4, .6, .5),
69
+ bbox_transform=ax.transAxes, loc=3)
70
+
71
+ # For visualization purposes we mark the bounding box by a rectangle
72
+ ax.add_patch(plt.Rectangle((.2, .4), .6, .5, ls="--", ec="c", fc="none",
73
+ transform=ax.transAxes))
74
+
75
+ # We set the axis limits to something other than the default, in order to not
76
+ # distract from the fact that axes coordinates are used here.
77
+ ax.set(xlim=(0, 10), ylim=(0, 10))
78
+
79
+
80
+ # Note how the two following insets are created at the same positions, one by
81
+ # use of the default parent axes' bbox and the other via a bbox in axes
82
+ # coordinates and the respective transform.
83
+ ax2 = fig.add_subplot(222)
84
+ axins2 = inset_axes(ax2, width="30%", height="50%")
85
+
86
+ ax3 = fig.add_subplot(224)
87
+ axins3 = inset_axes(ax3, width="100%", height="100%",
88
+ bbox_to_anchor=(.7, .5, .3, .5),
89
+ bbox_transform=ax3.transAxes)
90
+
91
+ # For visualization purposes we mark the bounding box by a rectangle
92
+ ax2.add_patch(plt.Rectangle((0, 0), 1, 1, ls="--", lw=2, ec="c", fc="none"))
93
+ ax3.add_patch(plt.Rectangle((.7, .5), .3, .5, ls="--", lw=2,
94
+ ec="c", fc="none"))
95
+
96
+ # Turn ticklabels off
97
+ for axi in [axins2, axins3, ax2, ax3]:
98
+ axi.tick_params(labelleft=False, labelbottom=False)
99
+
100
+ plt.show()
101
+
102
+
103
+ # %%
104
+ # In the above the axes transform together with 4-tuple bounding boxes has been
105
+ # used as it mostly is useful to specify an inset relative to the axes it is
106
+ # an inset to. However, other use cases are equally possible. The following
107
+ # example examines some of those.
108
+ #
109
+
110
+ fig = plt.figure(figsize=[5.5, 2.8])
111
+ ax = fig.add_subplot(131)
112
+
113
+ # Create an inset outside the axes
114
+ axins = inset_axes(ax, width="100%", height="100%",
115
+ bbox_to_anchor=(1.05, .6, .5, .4),
116
+ bbox_transform=ax.transAxes, loc=2, borderpad=0)
117
+ axins.tick_params(left=False, right=True, labelleft=False, labelright=True)
118
+
119
+ # Create an inset with a 2-tuple bounding box. Note that this creates a
120
+ # bbox without extent. This hence only makes sense when specifying
121
+ # width and height in absolute units (inches).
122
+ axins2 = inset_axes(ax, width=0.5, height=0.4,
123
+ bbox_to_anchor=(0.33, 0.25),
124
+ bbox_transform=ax.transAxes, loc=3, borderpad=0)
125
+
126
+
127
+ ax2 = fig.add_subplot(133)
128
+ ax2.set_xscale("log")
129
+ ax2.set(xlim=(1e-6, 1e6), ylim=(-2, 6))
130
+
131
+ # Create inset in data coordinates using ax.transData as transform
132
+ axins3 = inset_axes(ax2, width="100%", height="100%",
133
+ bbox_to_anchor=(1e-2, 2, 1e3, 3),
134
+ bbox_transform=ax2.transData, loc=2, borderpad=0)
135
+
136
+ # Create an inset horizontally centered in figure coordinates and vertically
137
+ # bound to line up with the axes.
138
+ from matplotlib.transforms import blended_transform_factory # noqa
139
+
140
+ transform = blended_transform_factory(fig.transFigure, ax2.transAxes)
141
+ axins4 = inset_axes(ax2, width="16%", height="34%",
142
+ bbox_to_anchor=(0, 0, 1, 1),
143
+ bbox_transform=transform, loc=8, borderpad=0)
144
+
145
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/inset_locator_demo2.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ====================
3
+ Inset locator demo 2
4
+ ====================
5
+
6
+ This demo shows how to create a zoomed inset via `.zoomed_inset_axes`.
7
+ In the first subplot an `.AnchoredSizeBar` shows the zoom effect.
8
+ In the second subplot a connection to the region of interest is
9
+ created via `.mark_inset`.
10
+
11
+ A version of the second subplot, not using the toolkit, is available in
12
+ :doc:`/gallery/subplots_axes_and_figures/zoom_inset_axes`.
13
+ """
14
+
15
+ import matplotlib.pyplot as plt
16
+ import numpy as np
17
+
18
+ from matplotlib import cbook
19
+ from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
20
+ from mpl_toolkits.axes_grid1.inset_locator import mark_inset, zoomed_inset_axes
21
+
22
+ fig, (ax, ax2) = plt.subplots(ncols=2, figsize=[6, 3])
23
+
24
+
25
+ # First subplot, showing an inset with a size bar.
26
+ ax.set_aspect(1)
27
+
28
+ axins = zoomed_inset_axes(ax, zoom=0.5, loc='upper right')
29
+ # fix the number of ticks on the inset axes
30
+ axins.yaxis.get_major_locator().set_params(nbins=7)
31
+ axins.xaxis.get_major_locator().set_params(nbins=7)
32
+ axins.tick_params(labelleft=False, labelbottom=False)
33
+
34
+
35
+ def add_sizebar(ax, size):
36
+ asb = AnchoredSizeBar(ax.transData,
37
+ size,
38
+ str(size),
39
+ loc=8,
40
+ pad=0.1, borderpad=0.5, sep=5,
41
+ frameon=False)
42
+ ax.add_artist(asb)
43
+
44
+ add_sizebar(ax, 0.5)
45
+ add_sizebar(axins, 0.5)
46
+
47
+
48
+ # Second subplot, showing an image with an inset zoom and a marked inset
49
+ Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy") # 15x15 array
50
+ extent = (-3, 4, -4, 3)
51
+ Z2 = np.zeros((150, 150))
52
+ ny, nx = Z.shape
53
+ Z2[30:30+ny, 30:30+nx] = Z
54
+
55
+ ax2.imshow(Z2, extent=extent, origin="lower")
56
+
57
+ axins2 = zoomed_inset_axes(ax2, zoom=6, loc=1)
58
+ axins2.imshow(Z2, extent=extent, origin="lower")
59
+
60
+ # subregion of the original image
61
+ x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
62
+ axins2.set_xlim(x1, x2)
63
+ axins2.set_ylim(y1, y2)
64
+ # fix the number of ticks on the inset axes
65
+ axins2.yaxis.get_major_locator().set_params(nbins=7)
66
+ axins2.xaxis.get_major_locator().set_params(nbins=7)
67
+ axins2.tick_params(labelleft=False, labelbottom=False)
68
+
69
+ # draw a bbox of the region of the inset axes in the parent axes and
70
+ # connecting lines between the bbox and the inset axes area
71
+ mark_inset(ax2, axins2, loc1=2, loc2=4, fc="none", ec="0.5")
72
+
73
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ====================================
3
+ Make room for ylabel using axes_grid
4
+ ====================================
5
+ """
6
+
7
+ import matplotlib.pyplot as plt
8
+
9
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
10
+ from mpl_toolkits.axes_grid1.axes_divider import make_axes_area_auto_adjustable
11
+
12
+ fig = plt.figure()
13
+ ax = fig.add_axes([0, 0, 1, 1])
14
+
15
+ ax.set_yticks([0.5], labels=["very long label"])
16
+
17
+ make_axes_area_auto_adjustable(ax)
18
+
19
+ # %%
20
+
21
+ fig = plt.figure()
22
+ ax1 = fig.add_axes([0, 0, 1, 0.5])
23
+ ax2 = fig.add_axes([0, 0.5, 1, 0.5])
24
+
25
+ ax1.set_yticks([0.5], labels=["very long label"])
26
+ ax1.set_ylabel("Y label")
27
+
28
+ ax2.set_title("Title")
29
+
30
+ make_axes_area_auto_adjustable(ax1, pad=0.1, use_axes=[ax1, ax2])
31
+ make_axes_area_auto_adjustable(ax2, pad=0.1, use_axes=[ax1, ax2])
32
+
33
+ # %%
34
+
35
+ fig = plt.figure()
36
+ ax1 = fig.add_axes([0, 0, 1, 1])
37
+ divider = make_axes_locatable(ax1)
38
+
39
+ ax2 = divider.append_axes("right", "100%", pad=0.3, sharey=ax1)
40
+ ax2.tick_params(labelleft=False)
41
+ fig.add_axes(ax2)
42
+
43
+ divider.add_auto_adjustable_area(use_axes=[ax1], pad=0.1,
44
+ adjust_dirs=["left"])
45
+ divider.add_auto_adjustable_area(use_axes=[ax2], pad=0.1,
46
+ adjust_dirs=["right"])
47
+ divider.add_auto_adjustable_area(use_axes=[ax1, ax2], pad=0.1,
48
+ adjust_dirs=["top", "bottom"])
49
+
50
+ ax1.set_yticks([0.5], labels=["very long label"])
51
+
52
+ ax2.set_title("Title")
53
+ ax2.set_xlabel("X - Label")
54
+
55
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/parasite_simple.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===============
3
+ Parasite Simple
4
+ ===============
5
+ """
6
+
7
+ import matplotlib.pyplot as plt
8
+
9
+ from mpl_toolkits.axes_grid1 import host_subplot
10
+
11
+ host = host_subplot(111)
12
+ par = host.twinx()
13
+
14
+ host.set_xlabel("Distance")
15
+ host.set_ylabel("Density")
16
+ par.set_ylabel("Temperature")
17
+
18
+ p1, = host.plot([0, 1, 2], [0, 1, 2], label="Density")
19
+ p2, = par.plot([0, 1, 2], [0, 3, 2], label="Temperature")
20
+
21
+ host.legend(labelcolor="linecolor")
22
+
23
+ host.yaxis.get_label().set_color(p1.get_color())
24
+ par.yaxis.get_label().set_color(p2.get_color())
25
+
26
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/parasite_simple2.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ================
3
+ Parasite Simple2
4
+ ================
5
+
6
+ """
7
+ import matplotlib.pyplot as plt
8
+
9
+ import matplotlib.transforms as mtransforms
10
+ from mpl_toolkits.axes_grid1.parasite_axes import HostAxes
11
+
12
+ obs = [["01_S1", 3.88, 0.14, 1970, 63],
13
+ ["01_S4", 5.6, 0.82, 1622, 150],
14
+ ["02_S1", 2.4, 0.54, 1570, 40],
15
+ ["03_S1", 4.1, 0.62, 2380, 170]]
16
+
17
+
18
+ fig = plt.figure()
19
+
20
+ ax_kms = fig.add_subplot(axes_class=HostAxes, aspect=1)
21
+
22
+ # angular proper motion("/yr) to linear velocity(km/s) at distance=2.3kpc
23
+ pm_to_kms = 1./206265.*2300*3.085e18/3.15e7/1.e5
24
+
25
+ aux_trans = mtransforms.Affine2D().scale(pm_to_kms, 1.)
26
+ ax_pm = ax_kms.twin(aux_trans)
27
+
28
+ for n, ds, dse, w, we in obs:
29
+ time = ((2007 + (10. + 4/30.)/12) - 1988.5)
30
+ v = ds / time * pm_to_kms
31
+ ve = dse / time * pm_to_kms
32
+ ax_kms.errorbar([v], [w], xerr=[ve], yerr=[we], color="k")
33
+
34
+
35
+ ax_kms.axis["bottom"].set_label("Linear velocity at 2.3 kpc [km/s]")
36
+ ax_kms.axis["left"].set_label("FWHM [km/s]")
37
+ ax_pm.axis["top"].set_label(r"Proper Motion [$''$/yr]")
38
+ ax_pm.axis["top"].label.set_visible(True)
39
+ ax_pm.axis["right"].major_ticklabels.set_visible(False)
40
+
41
+ ax_kms.set_xlim(950, 3700)
42
+ ax_kms.set_ylim(950, 3100)
43
+ # xlim and ylim of ax_pms will be automatically adjusted.
44
+
45
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/scatter_hist_locatable_axes.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================================
3
+ Scatter Histogram (Locatable Axes)
4
+ ==================================
5
+
6
+ Show the marginal distributions of a scatter plot as histograms at the sides of
7
+ the plot.
8
+
9
+ For a nice alignment of the main axes with the marginals, the axes positions
10
+ are defined by a ``Divider``, produced via `.make_axes_locatable`. Note that
11
+ the ``Divider`` API allows setting axes sizes and pads in inches, which is its
12
+ main feature.
13
+
14
+ If one wants to set axes sizes and pads relative to the main Figure, see the
15
+ :doc:`/gallery/lines_bars_and_markers/scatter_hist` example.
16
+ """
17
+
18
+ import matplotlib.pyplot as plt
19
+ import numpy as np
20
+
21
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
22
+
23
+ # Fixing random state for reproducibility
24
+ np.random.seed(19680801)
25
+
26
+ # the random data
27
+ x = np.random.randn(1000)
28
+ y = np.random.randn(1000)
29
+
30
+
31
+ fig, ax = plt.subplots(figsize=(5.5, 5.5))
32
+
33
+ # the scatter plot:
34
+ ax.scatter(x, y)
35
+
36
+ # Set aspect of the main axes.
37
+ ax.set_aspect(1.)
38
+
39
+ # create new axes on the right and on the top of the current axes
40
+ divider = make_axes_locatable(ax)
41
+ # below height and pad are in inches
42
+ ax_histx = divider.append_axes("top", 1.2, pad=0.1, sharex=ax)
43
+ ax_histy = divider.append_axes("right", 1.2, pad=0.1, sharey=ax)
44
+
45
+ # make some labels invisible
46
+ ax_histx.xaxis.set_tick_params(labelbottom=False)
47
+ ax_histy.yaxis.set_tick_params(labelleft=False)
48
+
49
+ # now determine nice limits by hand:
50
+ binwidth = 0.25
51
+ xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))
52
+ lim = (int(xymax/binwidth) + 1)*binwidth
53
+
54
+ bins = np.arange(-lim, lim + binwidth, binwidth)
55
+ ax_histx.hist(x, bins=bins)
56
+ ax_histy.hist(y, bins=bins, orientation='horizontal')
57
+
58
+ # the xaxis of ax_histx and yaxis of ax_histy are shared with ax,
59
+ # thus there is no need to manually adjust the xlim and ylim of these
60
+ # axis.
61
+
62
+ ax_histx.set_yticks([0, 50, 100])
63
+ ax_histy.set_xticks([0, 50, 100])
64
+
65
+ plt.show()
66
+
67
+ # %%
68
+ #
69
+ # .. admonition:: References
70
+ #
71
+ # The use of the following functions, methods, classes and modules is shown
72
+ # in this example:
73
+ #
74
+ # - `mpl_toolkits.axes_grid1.axes_divider.make_axes_locatable`
75
+ # - `matplotlib.axes.Axes.set_aspect`
76
+ # - `matplotlib.axes.Axes.scatter`
77
+ # - `matplotlib.axes.Axes.hist`
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_anchored_artists.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =======================
3
+ Simple Anchored Artists
4
+ =======================
5
+
6
+ This example illustrates the use of the anchored helper classes found in
7
+ :mod:`matplotlib.offsetbox` and in :mod:`mpl_toolkits.axes_grid1`.
8
+ An implementation of a similar figure, but without use of the toolkit,
9
+ can be found in :doc:`/gallery/misc/anchored_artists`.
10
+ """
11
+
12
+ import matplotlib.pyplot as plt
13
+
14
+
15
+ def draw_text(ax):
16
+ """
17
+ Draw two text-boxes, anchored by different corners to the upper-left
18
+ corner of the figure.
19
+ """
20
+ from matplotlib.offsetbox import AnchoredText
21
+ at = AnchoredText("Figure 1a",
22
+ loc='upper left', prop=dict(size=8), frameon=True,
23
+ )
24
+ at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
25
+ ax.add_artist(at)
26
+
27
+ at2 = AnchoredText("Figure 1(b)",
28
+ loc='lower left', prop=dict(size=8), frameon=True,
29
+ bbox_to_anchor=(0., 1.),
30
+ bbox_transform=ax.transAxes
31
+ )
32
+ at2.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
33
+ ax.add_artist(at2)
34
+
35
+
36
+ def draw_circle(ax):
37
+ """
38
+ Draw a circle in axis coordinates
39
+ """
40
+ from matplotlib.patches import Circle
41
+ from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDrawingArea
42
+ ada = AnchoredDrawingArea(20, 20, 0, 0,
43
+ loc='upper right', pad=0., frameon=False)
44
+ p = Circle((10, 10), 10)
45
+ ada.da.add_artist(p)
46
+ ax.add_artist(ada)
47
+
48
+
49
+ def draw_sizebar(ax):
50
+ """
51
+ Draw a horizontal bar with length of 0.1 in data coordinates,
52
+ with a fixed label underneath.
53
+ """
54
+ from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
55
+ asb = AnchoredSizeBar(ax.transData,
56
+ 0.1,
57
+ r"1$^{\prime}$",
58
+ loc='lower center',
59
+ pad=0.1, borderpad=0.5, sep=5,
60
+ frameon=False)
61
+ ax.add_artist(asb)
62
+
63
+
64
+ fig, ax = plt.subplots()
65
+ ax.set_aspect(1.)
66
+
67
+ draw_text(ax)
68
+ draw_circle(ax)
69
+ draw_sizebar(ax)
70
+
71
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axes_divider1.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =====================
3
+ Simple Axes Divider 1
4
+ =====================
5
+
6
+ See also :ref:`axes_grid`.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+
11
+ from mpl_toolkits.axes_grid1 import Divider, Size
12
+
13
+
14
+ def label_axes(ax, text):
15
+ """Place a label at the center of an Axes, and remove the axis ticks."""
16
+ ax.text(.5, .5, text, transform=ax.transAxes,
17
+ horizontalalignment="center", verticalalignment="center")
18
+ ax.tick_params(bottom=False, labelbottom=False,
19
+ left=False, labelleft=False)
20
+
21
+
22
+ # %%
23
+ # Fixed axes sizes; fixed paddings.
24
+
25
+ fig = plt.figure(figsize=(6, 6))
26
+ fig.suptitle("Fixed axes sizes, fixed paddings")
27
+
28
+ # Sizes are in inches.
29
+ horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]
30
+ vert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]
31
+
32
+ rect = (0.1, 0.1, 0.8, 0.8)
33
+ # Divide the axes rectangle into a grid with sizes specified by horiz * vert.
34
+ div = Divider(fig, rect, horiz, vert, aspect=False)
35
+
36
+ # The rect parameter will actually be ignored and overridden by axes_locator.
37
+ ax1 = fig.add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
38
+ label_axes(ax1, "nx=0, ny=0")
39
+ ax2 = fig.add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
40
+ label_axes(ax2, "nx=0, ny=2")
41
+ ax3 = fig.add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
42
+ label_axes(ax3, "nx=2, ny=2")
43
+ ax4 = fig.add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
44
+ label_axes(ax4, "nx=2, nx1=4, ny=0")
45
+
46
+ # %%
47
+ # Axes sizes that scale with the figure size; fixed paddings.
48
+
49
+ fig = plt.figure(figsize=(6, 6))
50
+ fig.suptitle("Scalable axes sizes, fixed paddings")
51
+
52
+ horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]
53
+ vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
54
+
55
+ rect = (0.1, 0.1, 0.8, 0.8)
56
+ # Divide the axes rectangle into a grid with sizes specified by horiz * vert.
57
+ div = Divider(fig, rect, horiz, vert, aspect=False)
58
+
59
+ # The rect parameter will actually be ignored and overridden by axes_locator.
60
+ ax1 = fig.add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
61
+ label_axes(ax1, "nx=0, ny=0")
62
+ ax2 = fig.add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
63
+ label_axes(ax2, "nx=0, ny=2")
64
+ ax3 = fig.add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
65
+ label_axes(ax3, "nx=2, ny=2")
66
+ ax4 = fig.add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
67
+ label_axes(ax4, "nx=2, nx1=4, ny=0")
68
+
69
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axes_divider3.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ =====================
3
+ Simple axes divider 3
4
+ =====================
5
+
6
+ See also :ref:`axes_grid`.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+
11
+ from mpl_toolkits.axes_grid1 import Divider
12
+ import mpl_toolkits.axes_grid1.axes_size as Size
13
+
14
+ fig = plt.figure(figsize=(5.5, 4))
15
+
16
+ # the rect parameter will be ignored as we will set axes_locator
17
+ rect = (0.1, 0.1, 0.8, 0.8)
18
+ ax = [fig.add_axes(rect, label="%d" % i) for i in range(4)]
19
+
20
+
21
+ horiz = [Size.AxesX(ax[0]), Size.Fixed(.5), Size.AxesX(ax[1])]
22
+ vert = [Size.AxesY(ax[0]), Size.Fixed(.5), Size.AxesY(ax[2])]
23
+
24
+ # divide the axes rectangle into grid whose size is specified by horiz * vert
25
+ divider = Divider(fig, rect, horiz, vert, aspect=False)
26
+
27
+
28
+ ax[0].set_axes_locator(divider.new_locator(nx=0, ny=0))
29
+ ax[1].set_axes_locator(divider.new_locator(nx=2, ny=0))
30
+ ax[2].set_axes_locator(divider.new_locator(nx=0, ny=2))
31
+ ax[3].set_axes_locator(divider.new_locator(nx=2, ny=2))
32
+
33
+ ax[0].set_xlim(0, 2)
34
+ ax[1].set_xlim(0, 1)
35
+
36
+ ax[0].set_ylim(0, 1)
37
+ ax[2].set_ylim(0, 2)
38
+
39
+ divider.set_aspect(1.)
40
+
41
+ for ax1 in ax:
42
+ ax1.tick_params(labelbottom=False, labelleft=False)
43
+
44
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axesgrid.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ================
3
+ Simple ImageGrid
4
+ ================
5
+
6
+ Align multiple images using `~mpl_toolkits.axes_grid1.axes_grid.ImageGrid`.
7
+ """
8
+
9
+ import matplotlib.pyplot as plt
10
+ import numpy as np
11
+
12
+ from mpl_toolkits.axes_grid1 import ImageGrid
13
+
14
+ im1 = np.arange(100).reshape((10, 10))
15
+ im2 = im1.T
16
+ im3 = np.flipud(im1)
17
+ im4 = np.fliplr(im2)
18
+
19
+ fig = plt.figure(figsize=(4., 4.))
20
+ grid = ImageGrid(fig, 111, # similar to subplot(111)
21
+ nrows_ncols=(2, 2), # creates 2x2 grid of axes
22
+ axes_pad=0.1, # pad between axes in inch.
23
+ )
24
+
25
+ for ax, im in zip(grid, [im1, im2, im3, im4]):
26
+ # Iterating over the grid returns the Axes.
27
+ ax.imshow(im)
28
+
29
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axesgrid2.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==================
3
+ Simple ImageGrid 2
4
+ ==================
5
+
6
+ Align multiple images of different sizes using
7
+ `~mpl_toolkits.axes_grid1.axes_grid.ImageGrid`.
8
+ """
9
+
10
+ import matplotlib.pyplot as plt
11
+
12
+ from matplotlib import cbook
13
+ from mpl_toolkits.axes_grid1 import ImageGrid
14
+
15
+ fig = plt.figure(figsize=(5.5, 3.5))
16
+ grid = ImageGrid(fig, 111, # similar to subplot(111)
17
+ nrows_ncols=(1, 3),
18
+ axes_pad=0.1,
19
+ label_mode="L",
20
+ )
21
+
22
+ # demo image
23
+ Z = cbook.get_sample_data("axes_grid/bivariate_normal.npy")
24
+ im1 = Z
25
+ im2 = Z[:, :10]
26
+ im3 = Z[:, 10:]
27
+ vmin, vmax = Z.min(), Z.max()
28
+ for ax, im in zip(grid, [im1, im2, im3]):
29
+ ax.imshow(im, origin="lower", vmin=vmin, vmax=vmax)
30
+
31
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_axisline4.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ================
3
+ Simple Axisline4
4
+ ================
5
+
6
+ """
7
+ import matplotlib.pyplot as plt
8
+ import numpy as np
9
+
10
+ from mpl_toolkits.axes_grid1 import host_subplot
11
+
12
+ ax = host_subplot(111)
13
+ xx = np.arange(0, 2*np.pi, 0.01)
14
+ ax.plot(xx, np.sin(xx))
15
+
16
+ ax2 = ax.twin() # ax2 is responsible for "top" axis and "right" axis
17
+ ax2.set_xticks([0., .5*np.pi, np.pi, 1.5*np.pi, 2*np.pi],
18
+ labels=["$0$", r"$\frac{1}{2}\pi$",
19
+ r"$\pi$", r"$\frac{3}{2}\pi$", r"$2\pi$"])
20
+
21
+ ax2.axis["right"].major_ticklabels.set_visible(False)
22
+ ax2.axis["top"].major_ticklabels.set_visible(True)
23
+
24
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axes_grid1/simple_colorbar.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ===============
3
+ Simple Colorbar
4
+ ===============
5
+
6
+ """
7
+ import matplotlib.pyplot as plt
8
+ import numpy as np
9
+
10
+ from mpl_toolkits.axes_grid1 import make_axes_locatable
11
+
12
+ ax = plt.subplot()
13
+ im = ax.imshow(np.arange(100).reshape((10, 10)))
14
+
15
+ # create an Axes on the right side of ax. The width of cax will be 5%
16
+ # of ax and the padding between cax and ax will be fixed at 0.05 inch.
17
+ divider = make_axes_locatable(ax)
18
+ cax = divider.append_axes("right", size="5%", pad=0.05)
19
+
20
+ plt.colorbar(im, cax=cax)
21
+
22
+ plt.show()
testbed/matplotlib__matplotlib/galleries/examples/axisartist/README.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ .. _axis_artist_examples:
2
+
3
+ .. _axisartist-examples-index:
4
+
5
+ Module - axisartist
6
+ ===================
testbed/matplotlib__matplotlib/galleries/examples/axisartist/axis_direction.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ==============
3
+ Axis Direction
4
+ ==============
5
+ """
6
+
7
+ import matplotlib.pyplot as plt
8
+
9
+ import mpl_toolkits.axisartist as axisartist
10
+
11
+
12
+ def setup_axes(fig, pos):
13
+ ax = fig.add_subplot(pos, axes_class=axisartist.Axes)
14
+
15
+ ax.set_ylim(-0.1, 1.5)
16
+ ax.set_yticks([0, 1])
17
+
18
+ ax.axis[:].set_visible(False)
19
+
20
+ ax.axis["x"] = ax.new_floating_axis(1, 0.5)
21
+ ax.axis["x"].set_axisline_style("->", size=1.5)
22
+
23
+ return ax
24
+
25
+
26
+ plt.rcParams.update({
27
+ "axes.titlesize": "medium",
28
+ "axes.titley": 1.1,
29
+ })
30
+
31
+ fig = plt.figure(figsize=(10, 4))
32
+ fig.subplots_adjust(bottom=0.1, top=0.9, left=0.05, right=0.95)
33
+
34
+ ax1 = setup_axes(fig, 251)
35
+ ax1.axis["x"].set_axis_direction("left")
36
+
37
+ ax2 = setup_axes(fig, 252)
38
+ ax2.axis["x"].label.set_text("Label")
39
+ ax2.axis["x"].toggle(ticklabels=False)
40
+ ax2.axis["x"].set_axislabel_direction("+")
41
+ ax2.set_title("label direction=$+$")
42
+
43
+ ax3 = setup_axes(fig, 253)
44
+ ax3.axis["x"].label.set_text("Label")
45
+ ax3.axis["x"].toggle(ticklabels=False)
46
+ ax3.axis["x"].set_axislabel_direction("-")
47
+ ax3.set_title("label direction=$-$")
48
+
49
+ ax4 = setup_axes(fig, 254)
50
+ ax4.axis["x"].set_ticklabel_direction("+")
51
+ ax4.set_title("ticklabel direction=$+$")
52
+
53
+ ax5 = setup_axes(fig, 255)
54
+ ax5.axis["x"].set_ticklabel_direction("-")
55
+ ax5.set_title("ticklabel direction=$-$")
56
+
57
+ ax7 = setup_axes(fig, 257)
58
+ ax7.axis["x"].label.set_text("rotation=10")
59
+ ax7.axis["x"].label.set_rotation(10)
60
+ ax7.axis["x"].toggle(ticklabels=False)
61
+
62
+ ax8 = setup_axes(fig, 258)
63
+ ax8.axis["x"].set_axislabel_direction("-")
64
+ ax8.axis["x"].label.set_text("rotation=10")
65
+ ax8.axis["x"].label.set_rotation(10)
66
+ ax8.axis["x"].toggle(ticklabels=False)
67
+
68
+ plt.show()