Skip to content

Commit e7f6eda

Browse files
committed
DOC: describe suppression of auto tick locator adjustment #2205
1 parent aa5d9b5 commit e7f6eda

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

doc/source/visualization.rst

+46-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ To plot data on a secondary y-axis, use the ``secondary_y`` keyword:
123123
Selective Plotting on Secondary Y-axis
124124
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125125

126-
To plot some columns in a DataFrame, give the column names to the `secondary_y`
126+
To plot some columns in a DataFrame, give the column names to the ``secondary_y``
127127
keyword:
128128

129129
.. ipython:: python
@@ -135,7 +135,7 @@ keyword:
135135
136136
Note that the columns plotted on the secondary y-axis is automatically marked
137137
with "(right)" in the legend. To turn off the automatic marking, use the
138-
`mark_right=False` keyword:
138+
``mark_right=False`` keyword:
139139

140140
.. ipython:: python
141141
@@ -145,6 +145,50 @@ with "(right)" in the legend. To turn off the automatic marking, use the
145145
df.plot(secondary_y=['A', 'B'], mark_right=False)
146146
147147
148+
Suppressing tick resolution adjustment
149+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150+
151+
Pandas includes automatically tick resolution adjustment for regular frequency
152+
time-series data. For limited cases where pandas cannot infer the frequency
153+
information (e.g., in an externally created ``twinx``), you can choose to
154+
suppress this behavior for alignment purposes.
155+
156+
Here is the default behavior, notice how the x-axis tick labelling is performed:
157+
158+
.. ipython:: python
159+
160+
plt.figure()
161+
162+
@savefig ser_plot_suppress.png width=4.5in
163+
df.A.plot()
164+
165+
166+
Using the ``x_compat`` parameter, you can suppress this bevahior:
167+
168+
.. ipython:: python
169+
170+
plt.figure()
171+
172+
@savefig ser_plot_suppress_parm.png width=4.5in
173+
df.A.plot(x_compat=True)
174+
175+
176+
If you have more than one plot that needs to be suppressed, the ``use`` method
177+
in ``pandas.plot_params`` can be used in a `with statement`:
178+
179+
.. ipython:: python
180+
181+
import pandas as pd
182+
183+
plt.figure()
184+
185+
@savefig ser_plot_suppress_context.png width=4.5in
186+
with pd.plot_params.use('x_compat', True):
187+
df.A.plot(color='r')
188+
df.B.plot(color='g')
189+
df.C.plot(color='b')
190+
191+
148192
Targeting different subplots
149193
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150194

0 commit comments

Comments
 (0)