Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 10 additions & 3 deletions python/pyspark/pandas/plot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,10 @@ def barh(self, x=None, y=None, **kwargs):

Parameters
----------
x : label or position, default DataFrame.index
Column to be used for categories.
y : label or position, default All numeric columns in dataframe
x : label or position, default All numeric columns in dataframe
Columns to be plotted from the DataFrame.
y : label or position, default DataFrame.index
Column to be used for categories.
**kwds
Keyword arguments to pass on to
:meth:`pyspark.pandas.DataFrame.plot` or :meth:`pyspark.pandas.Series.plot`.
Expand All @@ -770,6 +770,13 @@ def barh(self, x=None, y=None, **kwargs):
Return an custom object when ``backend!=plotly``.
Return an ndarray when ``subplots=True`` (matplotlib-only).

Notes
-----
In Plotly and Matplotlib, the interpretation of `x` and `y` for `barh` plots differs.
In Plotly, `x` refers to the values and `y` refers to the categories.
In Matplotlib, `x` refers to the categories and `y` refers to the values.
Ensure correct axis labeling based on the backend used.

See Also
--------
plotly.express.bar : Plot a vertical bar plot using plotly.
Expand Down
5 changes: 3 additions & 2 deletions python/pyspark/pandas/tests/plot/test_frame_plot_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def check_barh_plot_with_x_y(pdf, psdf, x, y):
self.assertEqual(pdf.plot.barh(x=x, y=y), psdf.plot.barh(x=x, y=y))

# this is testing plot with specified x and y
pdf1 = pd.DataFrame({"lab": ["A", "B", "C"], "val": [10, 30, 20]})
pdf1 = pd.DataFrame({"lab": ["A", "B", "C"], "val": [10, 30, 20], "val2": [1.1, 2.2, 3.3]})
psdf1 = ps.from_pandas(pdf1)
check_barh_plot_with_x_y(pdf1, psdf1, x="lab", y="val")
check_barh_plot_with_x_y(pdf1, psdf1, x="val", y="lab")
check_barh_plot_with_x_y(pdf1, psdf1, x=["val", "val2"], y="lab")

def test_barh_plot(self):
def check_barh_plot(pdf, psdf):
Expand Down