Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a690651

Browse filesBrowse files
committed
Clarify dollar_ticks example and FormatStrFormatter docs.
dollar_ticks only uses FormatStrFormatter implicitly.
1 parent c287b9f commit a690651
Copy full SHA for a690651

File tree

Expand file treeCollapse file tree

2 files changed

+15
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-4
lines changed

‎galleries/examples/ticks/dollar_ticks.py

Copy file name to clipboardExpand all lines: galleries/examples/ticks/dollar_ticks.py
+2-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,11 @@ class FormatStrFormatter(Formatter):
336336
The format string should have a single variable format (%) in it.
337337
It will be applied to the value (not the position) of the tick.
338338
339-
Negative numeric values will use a dash, not a Unicode minus; use mathtext
340-
to get a Unicode minus by wrapping the format specifier with $ (e.g.
341-
"$%g$").
339+
Negative numeric values (e.g., -1) will use a dash, not a Unicode minus;
340+
use mathtext to get a Unicode minus by wrapping the format specifier with $
341+
(e.g. "$%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 (e.g., -1) will use a dash, not a Unicode minus;
364+
use mathtext to get a Unicode minus by wrapping the format specifier with $
365+
(e.g. "${x}$").
366+
367+
It is typically unnecessary to explicitly construct `.StrMethodFormatter`
368+
objects, as `~.Axis.set_major_formatter` directly accepts the format string
369+
itself.
361370
"""
371+
362372
def __init__(self, fmt):
363373
self.fmt = fmt
364374

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.