pyspark.sql.plot.core.PySparkPlotAccessor.barh#

PySparkPlotAccessor.barh(x, y, **kwargs)[source]#

Make a horizontal bar plot.

A horizontal bar plot is a plot that presents quantitative data with rectangular bars with lengths proportional to the values that they represent. A bar plot shows comparisons among discrete categories. One axis of the plot shows the specific categories being compared, and the other axis represents a measured value.

Parameters
xstr or list of str

Name(s) of the column(s) to use for the horizontal axis. Multiple columns can be plotted.

ystr or list of str

Name(s) of the column(s) to use for the vertical axis. Multiple columns can be plotted.

**kwargsoptional

Additional keyword arguments.

Returns
plotly.graph_objs.Figure

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.

Examples

>>> data = [("A", 10, 1.5), ("B", 30, 2.5), ("C", 20, 3.5)]
>>> columns = ["category", "int_val", "float_val"]
>>> df = spark.createDataFrame(data, columns)
>>> df.plot.barh(x="int_val", y="category")  
>>> df.plot.barh(
...     x=["int_val", "float_val"], y="category"
... )