Skip to content

TYP: annotate plotting based on _get_axe_freq #35960

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4c5eddd
REF: remove unnecesary try/except
jbrockmendel Aug 21, 2020
c632c9f
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
9e64be3
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
42649fb
TST: add test for agg on ordered categorical cols (#35630)
mathurk1 Aug 21, 2020
47121dd
TST: resample does not yield empty groups (#10603) (#35799)
tkmz-n Aug 21, 2020
1decb3e
revert accidental rebase
jbrockmendel Aug 22, 2020
57c5dd3
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 22, 2020
a358463
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
ffa7ad7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
e5e98d4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
408db5a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
d3493cf
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
75a805a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
9f61070
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
2d10f6e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
3e20187
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
e27d07f
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 27, 2020
c52bed4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 27, 2020
b69d4d7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
1c5f8fd
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
0110932
TYP: annotate plotting based on _get_ax_freq
jbrockmendel Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from typing import List, Optional
from typing import TYPE_CHECKING, List, Optional
import warnings

from matplotlib.artist import Artist
Expand Down Expand Up @@ -43,6 +43,9 @@
table,
)

if TYPE_CHECKING:
from matplotlib.axes import Axes


class MPLPlot:
"""
Expand Down Expand Up @@ -1147,7 +1150,7 @@ def _plot(cls, ax, x, y, style=None, column_num=None, stacking_id=None, **kwds):
return lines

@classmethod
def _ts_plot(cls, ax, x, data, style=None, **kwds):
def _ts_plot(cls, ax: "Axes", x, data, style=None, **kwds):
from pandas.plotting._matplotlib.timeseries import (
_decorate_axes,
_maybe_resample,
Expand Down
21 changes: 11 additions & 10 deletions pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
from pandas.tseries.frequencies import get_period_alias, is_subperiod, is_superperiod

if TYPE_CHECKING:
from pandas import Index, Series # noqa:F401
from matplotlib.axes import Axes

from pandas import Index, Series # noqa:F401

# ---------------------------------------------------------------------
# Plotting functions and monkey patches


def _maybe_resample(series: "Series", ax, kwargs):
def _maybe_resample(series: "Series", ax: "Axes", kwargs):
# resample against axes freq if necessary
freq, ax_freq = _get_freq(ax, series)

Expand Down Expand Up @@ -74,7 +75,7 @@ def _is_sup(f1: str, f2: str) -> bool:
)


def _upsample_others(ax, freq, kwargs):
def _upsample_others(ax: "Axes", freq, kwargs):
legend = ax.get_legend()
lines, labels = _replot_ax(ax, freq, kwargs)
_replot_ax(ax, freq, kwargs)
Expand All @@ -97,7 +98,7 @@ def _upsample_others(ax, freq, kwargs):
ax.legend(lines, labels, loc="best", title=title)


def _replot_ax(ax, freq, kwargs):
def _replot_ax(ax: "Axes", freq, kwargs):
data = getattr(ax, "_plot_data", None)

# clear current axes and data
Expand Down Expand Up @@ -127,7 +128,7 @@ def _replot_ax(ax, freq, kwargs):
return lines, labels


def _decorate_axes(ax, freq, kwargs):
def _decorate_axes(ax: "Axes", freq, kwargs):
"""Initialize axes for time-series plotting"""
if not hasattr(ax, "_plot_data"):
ax._plot_data = []
Expand All @@ -143,7 +144,7 @@ def _decorate_axes(ax, freq, kwargs):
ax.date_axis_info = None


def _get_ax_freq(ax):
def _get_ax_freq(ax: "Axes"):
"""
Get the freq attribute of the ax object if set.
Also checks shared axes (eg when using secondary yaxis, sharex=True
Expand Down Expand Up @@ -174,7 +175,7 @@ def _get_period_alias(freq) -> Optional[str]:
return freq


def _get_freq(ax, series: "Series"):
def _get_freq(ax: "Axes", series: "Series"):
# get frequency from data
freq = getattr(series.index, "freq", None)
if freq is None:
Expand All @@ -192,7 +193,7 @@ def _get_freq(ax, series: "Series"):
return freq, ax_freq


def _use_dynamic_x(ax, data: "FrameOrSeriesUnion") -> bool:
def _use_dynamic_x(ax: "Axes", data: FrameOrSeriesUnion) -> bool:
freq = _get_index_freq(data.index)
ax_freq = _get_ax_freq(ax)

Expand Down Expand Up @@ -234,7 +235,7 @@ def _get_index_freq(index: "Index") -> Optional[BaseOffset]:
return freq


def _maybe_convert_index(ax, data):
def _maybe_convert_index(ax: "Axes", data):
# tsplot converts automatically, but don't want to convert index
# over and over for DataFrames
if isinstance(data.index, (ABCDatetimeIndex, ABCPeriodIndex)):
Expand Down Expand Up @@ -264,7 +265,7 @@ def _maybe_convert_index(ax, data):
# Do we need the rest for convenience?


def _format_coord(freq, t, y):
def _format_coord(freq, t, y) -> str:
time_period = Period(ordinal=int(t), freq=freq)
return f"t = {time_period} y = {y:8f}"

Expand Down