@@ -74,16 +74,16 @@ def plot_text(pos, text=None, ax=None, color=None, **kwargs):
74
74
return [handle ]
75
75
76
76
77
- def plot_point (pos , marker = "bs" , text = None , ax = None , textargs = None , ** kwargs ):
77
+ def plot_point (pos , marker = "bs" , label = None , text = None , ax = None , textargs = None , ** kwargs ):
78
78
"""
79
79
Plot a point using matplotlib
80
80
81
81
:param pos: position of marker
82
82
:type pos: array_like(2), ndarray(2,n), list of 2-tuples
83
83
:param marker: matplotlub marker style, defaults to 'bs'
84
84
:type marker: str or list of str, optional
85
- :param text : text label, defaults to None
86
- :type text : str, optional
85
+ :param label : text label, defaults to None
86
+ :type label : str, optional
87
87
:param ax: axes to plot in, defaults to ``gca()``
88
88
:type ax: Axis, optional
89
89
:return: the matplotlib object
@@ -101,8 +101,17 @@ def plot_point(pos, marker="bs", text=None, ax=None, textargs=None, **kwargs):
101
101
vertically aligned.
102
102
103
103
- Multiple points can be marked if ``pos`` is a 2xn array or a list of
104
- coordinate pairs. If a label is provided every point will have the same
105
- label.
104
+ coordinate pairs. In this case:
105
+ - all points have the same label
106
+ - label can include the format string {} which is susbstituted for the
107
+ point index, starting at zero
108
+ - label can be a tuple containing a format string followed by vectors
109
+ of shape(n). For example::
110
+
111
+ ``("#{0} a={1:.1f}, b={2:.1f}", a, b)``
112
+
113
+ will label each point with its index (argument 0) and consecutive
114
+ elements of ``a`` and ``b`` which are arguments 1 and 2 respectively.
106
115
107
116
Examples:
108
117
@@ -119,6 +128,10 @@ def plot_point(pos, marker="bs", text=None, ax=None, textargs=None, **kwargs):
119
128
- ``plot_point(p, 'r*', ('{1:.1f}', z))`` plot red star at points defined by
120
129
columns of ``p`` and label them all with successive elements of ``z``.
121
130
"""
131
+
132
+ if text is not None :
133
+ raise DeprecationWarning ('use label not text' )
134
+
122
135
if isinstance (pos , np .ndarray ):
123
136
if pos .ndim == 1 :
124
137
x = pos [0 ]
@@ -158,22 +171,22 @@ def plot_point(pos, marker="bs", text=None, ax=None, textargs=None, **kwargs):
158
171
handles .append (plt .plot (x , y , m , ** kwargs ))
159
172
else :
160
173
handles .append (plt .plot (x , y , marker , ** kwargs ))
161
- if text is not None :
174
+ if label is not None :
162
175
try :
163
176
xy = zip (x , y )
164
177
except TypeError :
165
178
xy = [(x , y )]
166
- if isinstance (text , str ):
179
+ if isinstance (label , str ):
167
180
# simple string, but might have format chars
168
181
for i , (x , y ) in enumerate (xy ):
169
- handles .append (plt .text (x , y , " " + text .format (i ), ** textopts ))
170
- elif isinstance (text , (tuple , list )):
182
+ handles .append (plt .text (x , y , " " + label .format (i ), ** textopts ))
183
+ elif isinstance (label , (tuple , list )):
171
184
for i , (x , y ) in enumerate (xy ):
172
185
handles .append (
173
186
plt .text (
174
187
x ,
175
188
y ,
176
- " " + text [0 ].format (i , * [d [i ] for d in text [1 :]]),
189
+ " " + label [0 ].format (i , * [d [i ] for d in label [1 :]]),
177
190
** textopts
178
191
)
179
192
)
0 commit comments