|
75 | 75 | ],
|
76 | 76 | [".version.__version__"],
|
77 | 77 | )
|
| 78 | + |
| 79 | + |
| 80 | +def plot(data_frame, kind, **kwargs): |
| 81 | + """ |
| 82 | + Pandas plotting backend function, not meant to be called directly. |
| 83 | + To activate, set pandas.options.plotting.backend="plotly.express.pandas_backend" |
| 84 | + See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py |
| 85 | + """ |
| 86 | + from .express import scatter, line, area, bar, box, histogram |
| 87 | + |
| 88 | + if kind == "scatter": |
| 89 | + new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["s", "c"]} |
| 90 | + return scatter(data_frame, **new_kwargs) |
| 91 | + if kind == "line": |
| 92 | + return line(data_frame, **kwargs) |
| 93 | + if kind == "area": |
| 94 | + return area(data_frame, **kwargs) |
| 95 | + if kind == "bar": |
| 96 | + return bar(data_frame, **kwargs) |
| 97 | + if kind == "barh": |
| 98 | + return bar(data_frame, orientation="h", **kwargs) |
| 99 | + if kind == "box": |
| 100 | + new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["by"]} |
| 101 | + return box(data_frame, **new_kwargs) |
| 102 | + if kind in "hist": |
| 103 | + new_kwargs = {k: kwargs[k] for k in kwargs if k not in ["by", "bins"]} |
| 104 | + return histogram(data_frame, **new_kwargs) |
| 105 | + raise NotImplementedError( |
| 106 | + "The plotly.express backend doesn't yet support kind='%s'" % kind |
| 107 | + ) |
| 108 | + |
| 109 | + |
| 110 | +def boxplot_frame(data_frame, **kwargs): |
| 111 | + """ |
| 112 | + Pandas plotting backend function, not meant to be called directly. |
| 113 | + To activate, set pandas.options.plotting.backend="plotly.express.pandas_backend" |
| 114 | + See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py |
| 115 | + """ |
| 116 | + from .express import box |
| 117 | + |
| 118 | + skip = ["by", "column", "ax", "fontsize", "rot", "grid", "figsize", "layout"] |
| 119 | + skip += ["return_type"] |
| 120 | + new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip} |
| 121 | + return box(data_frame, **new_kwargs) |
| 122 | + |
| 123 | + |
| 124 | +def hist_frame(data_frame, **kwargs): |
| 125 | + """ |
| 126 | + Pandas plotting backend function, not meant to be called directly. |
| 127 | + To activate, set pandas.options.plotting.backend="plotly.express.pandas_backend" |
| 128 | + See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py |
| 129 | + """ |
| 130 | + from .express import histogram |
| 131 | + |
| 132 | + skip = ["column", "by", "grid", "xlabelsize", "xrot", "ylabelsize", "yrot"] |
| 133 | + skip += ["ax", "sharex", "sharey", "figsize", "layout", "bins"] |
| 134 | + new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip} |
| 135 | + return histogram(data_frame, **new_kwargs) |
| 136 | + |
| 137 | + |
| 138 | +def hist_series(data_frame, **kwargs): |
| 139 | + """ |
| 140 | + Pandas plotting backend function, not meant to be called directly. |
| 141 | + To activate, set pandas.options.plotting.backend="plotly.express.pandas_backend" |
| 142 | + See https://github.com/pandas-dev/pandas/blob/master/pandas/plotting/__init__.py |
| 143 | + """ |
| 144 | + from .express import histogram |
| 145 | + |
| 146 | + skip = ["by", "grid", "xlabelsize", "xrot", "ylabelsize", "yrot", "ax"] |
| 147 | + skip += ["figsize", "bins"] |
| 148 | + new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip} |
| 149 | + return histogram(data_frame, **new_kwargs) |
0 commit comments