Chapter 9 of 'Data Visualization Using Python' covers the Plotly Python package, which is an open-source library for creating interactive visualizations. It details various types of plots such as scatter plots, bar plots, pie charts, and more, providing step-by-step instructions for generating each type using Python code. The chapter emphasizes the versatility of Plotly for both offline and online visualizations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
7 views
Chapter 9-Plotly for Data Visualization
Chapter 9 of 'Data Visualization Using Python' covers the Plotly Python package, which is an open-source library for creating interactive visualizations. It details various types of plots such as scatter plots, bar plots, pie charts, and more, providing step-by-step instructions for generating each type using Python code. The chapter emphasizes the versatility of Plotly for both offline and online visualizations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29
Chapter 9
Plotly for Data Visualization
“Data Visualization Using Python”
Raj Kumar Samanta Ref: Seema Acharya, Wiley India Pvt. Ltd. In the presentation
► Plotly Python Package
► Scatter Plot ► Bar Plot ► Pie Chart ► Word Cloud ► Treemap ► Choropleth Chart ► Area Chart ► Bubble Chart ► Gantt Chart ► Boxplot ► Violin plot ► Histogram Plotly Python Package Plotly is Python’s graphing open-source library that makes interactive and publication- ready visualizations. The visualizations and graphs thus created, can be viewed both offline and online. It supports various types of plots like line charts, scatter plots, histograms, and box plots. Plotly has three main modules: ► plotly.plotly ► potly.graph_objs ► plotly.tools Plotly Python Package Plotly Python Package Scatter Plot To plot a scatter plot Plotly Python Package Scatter Plot To plot a scatter plot Plotly Python Package Bar Plot To plot a Bar plot Plotly Python Package Bar Plot Plotly Python Package Pie Chart To plot a Pie Chart ► Import the required Python libraries. ► Read in data from the csv, “iris.csv” into the Pandas DataFrame, “iris”. ► Group the data from the DataFrame, “iris” by “species”. ► Import “plotly.graph_objs” module and set “go” as the alias for it. ► Create the trace using the Pie function. Plotly Python Package Pie Chart Plotly Python Package Word Cloud To plot a word cloud ► Import the required Python libraries. ► import pandas as pd ► Read in data from the Excel, “ShakespearSonnet.xlsx” into the Pandas DataFrame, “df”. ► Import the required Python libraries, “WordCloud” and “matplotlib.pyplot”. Set the alias for “matplotlib. pyplot” as “plt”. ► text=" ".join(Sonnet_words for Sonnet_words in df.Sonnet_words) ► word_cloud = WordCloud(collocations = False, background_color = 'White').generate(text) plt.imshow(word_cloud, interpolation='bilinear') plt.axis('off') plt.show() Plotly Python Package Word Cloud Plotly Python Package Treemap To plot a Treemap. ► Import the required Python library, “pandas” and set “pd” as the alias for “pandas”. ► Read in data from the Excel, “Superstore.xlsx” into the Pandas DataFrame, “df ”. Validate that the data have been read in correctly by printing the first five observations from the DataFrame. import pandas as pd df = pd.read_excel("C:/data/Superstore.xlsx") df.head() Plotly Python Package Treemap Plotly Python Package Choropleth Chart To plot a Choropleth chart. ► Import Python libraries, “pandas” and “plotly.express”. Set “pd” as the alias for Pandas and “px” as the alias for plotly.express. import pandas as pd import plotly.express as px ► Import data from “Us_grexports.txt” into DataFrame, “data”. data = pd.read_csv('c:/data/Us_agr_exports.txt') Plotly Python Package Choropleth Chart Plotly Python Package Area Chart To plot an Area chart. ► Import the required Python library, “pandas”. Set “pd” as the alias for it. Import “plotly.express” and set “px” as the alias for it. ► Read in data from the csv, “iris.csv” into the Pandas DataFrame, “df ”. import pandas as pd import plotly.express as px df = pd.read_csv("c:/data/iris.csv", names=["sepal_length", "sepal_ width", "petal_length", "petal_width", "species"]) print(df.head()) ► Plot the area chart using data from the DataFrame, “df ”. Plotly Python Package Area Chart Plotly Python Package Bubble Chart To plot a Bubble chart. import plotly.express as px df = px.data.gapminder() fig = px.scatter(df.query("year==2007"), x="gdpPercap", y="lifeExp", size="pop", color="continent", hover_name="country", log_x=True, size_max=60) fig.show() Plotly Python Package Bubble Chart Plotly Python Package Gantt Chart Plotly Python Package Gantt Chart Plotly Python Package Boxplot To plot a boxplot. ► Import plotly.express and set the alias to “px”. ► Import numpy and set the alias to “np”. ► Create the data. ► Plot the boxplot using px.box(). Use “y” parameter to plot a vertical boxplot and “x” parameter to plot a horizontal boxplot. Plotly Python Package Boxplot Plotly Python Package Violin plot To plot a Violin plot. ► Import plotly.express and set the alias to “px”. ► Import numpy and set the alias to “np”. ► Create the data. ► Plot the violin plot using px.violin(). Use “y” parameter to plot a vertical violin plot and “x” parameter to plot a horizontal violin plot. Plotly Python Package Violin plot Plotly Python Package Histogram To plot a Histogram plot. ► Import plotly.express and set the alias to “px”. ► Import Pandas and set the alias to “pd”. ► Read in the data from “OlympicAthletes.xlsx” into the DataFrame, “df ”. ► Plot the histogram plot using px.histogram(). ► Set x to the “Age” column and color to “Total Medals”. Plotly Python Package Histogram Thank you
Immediate download Hypothesis Generation and Interpretation: Design Principles and Patterns for Big Data Applications 1st Edition Hiroshi Ishikawa ebooks 2024