8000 Clarify dollar_ticks example and FormatStrFormatter docs. · matplotlib/matplotlib@0bbaa8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0bbaa8c

Browse files
committed
Clarify dollar_ticks example and FormatStrFormatter docs.
dollar_ticks only uses FormatStrFormatter implicitly.
1 parent c287b9f commit 0bbaa8c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

galleries/examples/ticks/dollar_ticks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
Dollar ticks
44
============
55
6-
Use a `~.ticker.FormatStrFormatter` to prepend dollar signs on y-axis labels.
6+
Use a format string to prepend dollar signs on y-axis labels.
77
88
.. redirect-from:: /gallery/pyplots/dollar_ticks
99
"""
10+
1011
import matplotlib.pyplot as plt
1112
import numpy as np
1213

lib/matplotlib/ticker.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ class FormatStrFormatter(Formatter):
340340
to get a Unicode minus by wrapping the format specifier with $ (e.g.
341341
"$%g$").
342342
"""
343+
343344
def __init__(self, fmt):
344345
self.fmt = fmt
345346

@@ -358,7 +359,16 @@ class StrMethodFormatter(Formatter):
358359
359360
The field used for the tick value must be labeled *x* and the field used
360361
for the tick position must be labeled *pos*.
362+
363+
Negative numeric values will use a dash, not a Unicode minus; use mathtext
364+
to get a Unicode minus by wrapping the format specifier with $ (e.g.
365+
"${x}$").
366+
367+
It is typically unnecessary to explicitly construct `.StrMethodFormatter`
368+
objects, as `~.Axis.set_major_formatter` also directly accepts the format
369+
string itself.
361370
"""
371+
362372
def __init__(self, fmt):
363373
self.fmt = fmt
364374

0 commit comments

Comments
 (0)
0