File tree Expand file tree Collapse file tree 1 file changed +15
-15
lines changed
examples/subplots_axes_and_figures Expand file tree Collapse file tree 1 file changed +15
-15
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
- ============
3
- Subplot Demo
4
- ============
2
+ ==================
3
+ Basic Subplot Demo
4
+ ==================
5
5
6
- Simple demo with multiple subplots.
6
+ Demo with two subplots.
7
+ For more options, see
8
+ :ref:`sphx_glr_examples_subplots_axes_and_figures_subplots_demo.py`
7
9
"""
8
10
import numpy as np
9
11
import matplotlib .pyplot as plt
10
12
11
-
13
+ # Data for plotting
12
14
x1 = np .linspace (0.0 , 5.0 )
13
15
x2 = np .linspace (0.0 , 2.0 )
14
-
15
16
y1 = np .cos (2 * np .pi * x1 ) * np .exp (- x1 )
16
17
y2 = np .cos (2 * np .pi * x2 )
17
18
18
- plt .subplot (2 , 1 , 1 )
19
- plt .plot (x1 , y1 , 'ko-' )
20
- plt .title ('A tale of 2 subplots' )
21
- plt .ylabel ('Damped oscillation' )
19
+ # Create two subplots sharing y axis
20
+ fig , (ax1 , ax2 ) = plt .subplots (2 , sharey = True )
21
+
22
+ ax1 .plot (x1 , y1 , 'ko-' )
23
+ ax1 .set (title = 'A tale of 2 subplots' , ylabel = 'Damped oscillation' )
22
24
23
- plt .subplot (2 , 1 , 2 )
24
- plt .plot (x2 , y2 , 'r.-' )
25
- plt .xlabel ('time (s)' )
26
- plt .ylabel ('Undamped' )
25
+ ax2 .plot (x2 , y2 , 'r.-' )
26
+ ax2 .set (xlabel = 'time (s)' , ylabel = 'Undamped' )
27
27
28
- plt .show ()
28
+ plt .show ()
You can’t perform that action at this time.
0 commit comments