Skip to content

Commit aef0c1b

Browse files
committed
change text argument to label
1 parent 615fe3e commit aef0c1b

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

spatialmath/base/graphics.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ def plot_text(pos, text=None, ax=None, color=None, **kwargs):
7474
return [handle]
7575

7676

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):
7878
"""
7979
Plot a point using matplotlib
8080
8181
:param pos: position of marker
8282
:type pos: array_like(2), ndarray(2,n), list of 2-tuples
8383
:param marker: matplotlub marker style, defaults to 'bs'
8484
: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
8787
:param ax: axes to plot in, defaults to ``gca()``
8888
:type ax: Axis, optional
8989
:return: the matplotlib object
@@ -101,8 +101,17 @@ def plot_point(pos, marker="bs", text=None, ax=None, textargs=None, **kwargs):
101101
vertically aligned.
102102
103103
- 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.
106115
107116
Examples:
108117
@@ -119,6 +128,10 @@ def plot_point(pos, marker="bs", text=None, ax=None, textargs=None, **kwargs):
119128
- ``plot_point(p, 'r*', ('{1:.1f}', z))`` plot red star at points defined by
120129
columns of ``p`` and label them all with successive elements of ``z``.
121130
"""
131+
132+
if text is not None:
133+
raise DeprecationWarning('use label not text')
134+
122135
if isinstance(pos, np.ndarray):
123136
if pos.ndim == 1:
124137
x = pos[0]
@@ -158,22 +171,22 @@ def plot_point(pos, marker="bs", text=None, ax=None, textargs=None, **kwargs):
158171
handles.append(plt.plot(x, y, m, **kwargs))
159172
else:
160173
handles.append(plt.plot(x, y, marker, **kwargs))
161-
if text is not None:
174+
if label is not None:
162175
try:
163176
xy = zip(x, y)
164177
except TypeError:
165178
xy = [(x, y)]
166-
if isinstance(text, str):
179+
if isinstance(label, str):
167180
# simple string, but might have format chars
168181
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)):
171184
for i, (x, y) in enumerate(xy):
172185
handles.append(
173186
plt.text(
174187
x,
175188
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:]]),
177190
**textopts
178191
)
179192
)

0 commit comments

Comments
 (0)