[SPARK-50054][PYTHON][CONNECT] Support histogram plots#48578
Closed
xinrong-meng wants to merge 4 commits intoapache:masterfrom
Closed
[SPARK-50054][PYTHON][CONNECT] Support histogram plots#48578xinrong-meng wants to merge 4 commits intoapache:masterfrom
xinrong-meng wants to merge 4 commits intoapache:masterfrom
Conversation
Member
Author
|
The logic for constructing the histogram is mostly copied from Pandas on Spark to maintain parity. We can refactor it for reuse in a follow-up. |
Member
Author
|
@zhengruifeng @HyukjinKwon may I get a review please? |
zhengruifeng
approved these changes
Oct 22, 2024
Contributor
|
merged to master |
ericm-db
pushed a commit
to ericm-db/spark
that referenced
this pull request
Oct 22, 2024
### What changes were proposed in this pull request? Support histogram plots with plotly backend on both Spark Connect and Spark classic. ### Why are the changes needed? While Pandas on Spark supports plotting, PySpark currently lacks this feature. The proposed API will enable users to generate visualizations. This will provide users with an intuitive, interactive way to explore and understand large datasets directly from PySpark DataFrames, streamlining the data analysis workflow in distributed environments. See more at [PySpark Plotting API Specification](https://docs.google.com/document/d/1IjOEzC8zcetG86WDvqkereQPj_NGLNW7Bdu910g30Dg/edit?usp=sharing) in progress. Part of https://issues.apache.org/jira/browse/SPARK-49530. ### Does this PR introduce _any_ user-facing change? Yes. Histogram plots are supported as shown below. ```py >>> data = [(5.1, 3.5, 0), (4.9, 3.0, 0), (7.0, 3.2, 1), (6.4, 3.2, 1), (5.9, 3.0, 2)] >>> columns = ["length", "width", "species"] >>> df = spark.createDataFrame(data, columns) >>> fig1 = df.plot.hist(column=['length','width'], bins=4) >>> fig1.show() # see below >>> fig2 = df.plot(kind="hist",column='length', bins=4) >>> fig2.show() # see below ``` fig1:  fig2:  ### How was this patch tested? Unit tests. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#48578 from xinrong-meng/histogram. Authored-by: Xinrong Meng <xinrong@apache.org> Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
Member
Author
|
Thank you @zhengruifeng ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Support histogram plots with plotly backend on both Spark Connect and Spark classic.
Why are the changes needed?
While Pandas on Spark supports plotting, PySpark currently lacks this feature. The proposed API will enable users to generate visualizations. This will provide users with an intuitive, interactive way to explore and understand large datasets directly from PySpark DataFrames, streamlining the data analysis workflow in distributed environments.
See more at PySpark Plotting API Specification in progress.
Part of https://issues.apache.org/jira/browse/SPARK-49530.
Does this PR introduce any user-facing change?
Yes. Histogram plots are supported as shown below.
fig1:

fig2:

How was this patch tested?
Unit tests.
Was this patch authored or co-authored using generative AI tooling?
No.