1from __future__ import annotations
2
3from typing import TYPE_CHECKING
4
5from pandas.plotting._matplotlib.boxplot import (
6 BoxPlot,
7 boxplot,
8 boxplot_frame,
9 boxplot_frame_groupby,
10)
11from pandas.plotting._matplotlib.converter import (
12 deregister,
13 register,
14)
15from pandas.plotting._matplotlib.core import (
16 AreaPlot,
17 BarhPlot,
18 BarPlot,
19 HexBinPlot,
20 LinePlot,
21 PiePlot,
22 ScatterPlot,
23)
24from pandas.plotting._matplotlib.hist import (
25 HistPlot,
26 KdePlot,
27 hist_frame,
28 hist_series,
29)
30from pandas.plotting._matplotlib.misc import (
31 andrews_curves,
32 autocorrelation_plot,
33 bootstrap_plot,
34 lag_plot,
35 parallel_coordinates,
36 radviz,
37 scatter_matrix,
38)
39from pandas.plotting._matplotlib.tools import table
40
41if TYPE_CHECKING:
42 from pandas.plotting._matplotlib.core import MPLPlot
43
44PLOT_CLASSES: dict[str, type[MPLPlot]] = {
45 "line": LinePlot,
46 "bar": BarPlot,
47 "barh": BarhPlot,
48 "box": BoxPlot,
49 "hist": HistPlot,
50 "kde": KdePlot,
51 "area": AreaPlot,
52 "pie": PiePlot,
53 "scatter": ScatterPlot,
54 "hexbin": HexBinPlot,
55}
56
57
58def plot(data, kind, **kwargs):
59 # Importing pyplot at the top of the file (before the converters are
60 # registered) causes problems in matplotlib 2 (converters seem to not
61 # work)
62 import matplotlib.pyplot as plt
63
64 if kwargs.pop("reuse_plot", False):
65 ax = kwargs.get("ax")
66 if ax is None and len(plt.get_fignums()) > 0:
67 with plt.rc_context():
68 ax = plt.gca()
69 kwargs["ax"] = getattr(ax, "left_ax", ax)
70 plot_obj = PLOT_CLASSES[kind](data, **kwargs)
71 plot_obj.generate()
72 plot_obj.draw()
73 return plot_obj.result
74
75
76__all__ = [
77 "plot",
78 "hist_series",
79 "hist_frame",
80 "boxplot",
81 "boxplot_frame",
82 "boxplot_frame_groupby",
83 "table",
84 "andrews_curves",
85 "autocorrelation_plot",
86 "bootstrap_plot",
87 "lag_plot",
88 "parallel_coordinates",
89 "radviz",
90 "scatter_matrix",
91 "register",
92 "deregister",
93]