8000 MEP12 on set_and_get.py · matplotlib/matplotlib@982cecd · GitHub
[go: up one dir, main page]

Skip to content

Commit 982cecd

Browse files
committed
MEP12 on set_and_get.py
1 parent ecce9a1 commit 982cecd

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed
Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
"""
22
3-
MATLAB and pylab allow you to use setp and get to set and get
3+
MATLAB and pyplot allow you to use setp and get to set and get
44
object properties, as well as to do introspection on the object
55
66
set
77
To set the linestyle of a line to be dashed, you can do
88
9-
>>> line, = plot([1,2,3])
10-
>>> setp(line, linestyle='--')
9+
>>> line, = plt.plot([1,2,3])
10+
>>> plt.setp(line, linestyle='--')
1111
1212
If you want to know the valid types of arguments, you can provide the
1313
name of the property you want to set without a value
1414
15-
>>> setp(line, 'linestyle')
15+
>>> plt.setp(line, 'linestyle')
1616
linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
1717
1818
If you want to see all the properties that can be set, and their
1919
possible values, you can do
2020
21-
>>> setp(line)
21+
>>> plt.setp(line)
2222
2323
set operates on a single instance or a list of instances. If you are
2424
in query mode introspecting the possible values, only the first
2525
instance in the sequence is used. When actually setting values, all
2626
the instances will be set. e.g., suppose you have a list of two lines,
2727
the following will make both lines thicker and red
2828
29-
>>> x = arange(0,1.0,0.01)
30-
>>> y1 = sin(2*pi*x)
31-
>>> y2 = sin(4*pi*x)
32-
>>> lines = plot(x, y1, x, y2)
33-
>>> setp(lines, linewidth=2, color='r')
29+
>>> x = np.arange(0,1.0,0.01)
30+
>>> y1 = np.sin(2*np.pi*x)
31+
>>> y2 = np.sin(4*np.pi*x)
32+
>>> lines = plt.plot(x, y1, x, y2)
33+
>>> plt.setp(lines, linewidth=2, color='r')
3434
3535
3636
get:
3737
3838
get returns the value of a given attribute. You can use get to query
3939
the value of a single attribute
4040
41-
>>> getp(line, 'linewidth')
41+
>>> plt.getp(line, 'linewidth')
4242
0.5
4343
4444
or all the attribute/value pairs
4545
46-
>>> getp(line)
46+
>>> plt.getp(line)
4747
aa = True
4848
alpha = 1.0
4949
antialiased = True
@@ -65,33 +65,35 @@
6565
"""
6666

6767
from __future__ import print_function
68-
from pylab import *
68+
# from pylab import *
69+
import matplotlib.pyplot as plt
70+
import numpy as np
6971

7072

71-
x = arange(0, 1.0, 0.01)
72-
y1 = sin(2*pi*x)
73-
y2 = sin(4*pi*x)
74-
lines = plot(x, y1, x, y2)
73+
x = np.arange(0, 1.0, 0.01)
74+
y1 = np.sin(2*np.pi*x)
75+
y2 = np.sin(4*np.pi*x)
76+
lines = plt.plot(x, y1, x, y2)
7577
l1, l2 = lines
76-
setp(lines, linestyle='--') # set both to dashed
77-
setp(l1, linewidth=2, color='r') # line1 is thick and red
78-
setp(l2, linewidth=1, color='g') # line2 is thicker and green
78+
plt.setp(lines, linestyle='--') # set both to dashed
79+
plt.setp(l1, linewidth=2, color='r') # line1 is thick and red
80+
plt.setp(l2, linewidth=1, color='g') # line2 is thicker and green
7981

8082

8183
print('Line setters')
82-
setp(l1)
84+
plt.setp(l1)
8385
print('Line getters')
84-
getp(l1)
86+
plt.getp(l1)
8587

8688
print('Rectangle setters')
87-
setp(gca().patch)
89+
plt.setp(plt.gca().patch)
8890
print('Rectangle getters')
89-
getp(gca().patch)
91+
plt.getp(plt.gca().patch)
9092

91-
t = title('Hi mom')
93+
t = plt.title('Hi mom')
9294
print('Text setters')
93-
setp(t)
95+
plt.setp(t)
9496
print('Text getters')
95-
getp(t)
97+
plt.getp(t)
9698

97-
show()
99+
plt.show()

0 commit comments

Comments
 (0)
0