Skip to content

Commit 90d9e25

Browse files
authored
DOC: Fixing EX01 - Added examples (#54351)
* Example register_matplotlib_converters * Changed/added explanation to example * Fixing plot
1 parent 2c1ec41 commit 90d9e25

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
6565
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
6666
pandas.io.stata.StataWriter.write_file \
6767
pandas.plotting.deregister_matplotlib_converters \
68-
pandas.plotting.register_matplotlib_converters \
6968
pandas.api.extensions.ExtensionArray \
7069
RET=$(($RET + $?)) ; echo $MSG "DONE"
7170

pandas/plotting/_misc.py

+23
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ def register() -> None:
8181
See Also
8282
--------
8383
deregister_matplotlib_converters : Remove pandas formatters and converters.
84+
85+
Examples
86+
--------
87+
.. plot::
88+
:context: close-figs
89+
90+
The following line is done automatically by pandas so
91+
the plot can be rendered:
92+
93+
>>> pd.plotting.register_matplotlib_converters()
94+
95+
>>> df = pd.DataFrame({'ts': pd.period_range('2020', periods=2, freq='M'),
96+
... 'y': [1, 2]
97+
... })
98+
>>> plot = df.plot.line(x='ts', y='y')
99+
100+
Unsetting the register manually an error will be raised:
101+
102+
>>> pd.set_option("plotting.matplotlib.register_converters",
103+
... False) # doctest: +SKIP
104+
>>> df.plot.line(x='ts', y='y') # doctest: +SKIP
105+
Traceback (most recent call last):
106+
TypeError: float() argument must be a string or a real number, not 'Period'
84107
"""
85108
plot_backend = _get_plot_backend("matplotlib")
86109
plot_backend.register()

0 commit comments

Comments
 (0)