Let’s Create Some Charts using Python Plotly.

Aswin Satheesh
featurepreneur
Published in
3 min readSep 3, 2021

What is Python Plotly ?

The Plotly Python library is an interactive open-source library. This can be a very helpful tool for data visualization and understanding the data simply and easily. plotly graph objects are a high-level interface to plotly which are easy to use. It can plot various types of graphs and charts like scatter plots, line charts, bar charts, box plots, histograms, pie charts, etc.

  • To install Plotly in python ,type the below command in the terminal.
pip install plotly
  1. Line Chart

Line charts are used to represent the relation between two data X and Y on a different axis.

import plotly.express as px
df = px.data.iris()
# plotting the line chart
fig = px.line(df, x="species", y="petal_width")
# showing the plot
fig.show()
line-chart

2 . Bar Chart

A bar chart is a pictorial representation of data that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent.

import plotly.express as pxdf = px.data.iris()# plotting the bar chartfig = px.bar(df, x="sepal_width", y="sepal_length")# showing the plotfig.show()
bar-chart

3. Histogram

A histogram is a graphical representation that organizes a group of data points into user-specified ranges.

import plotly.express as pxdf = px.data.iris()# plotting the histogram
fig = px.histogram(df, x="sepal_length", y="petal_width")
# showing the plot
fig.show()
histogram

4. Scatter Plot

A scatter plot is a set of points plotted on a horizontal and vertical axes. Scatter plots are important in statistics because they can show the extent of correlation, if any, between the values of observed quantities or phenomena (called variables).

import plotly.express as pxdf = px.data.iris()# plotting the scatter chart
fig = px.scatter(df, x="species", y="petal_width")
# showing the plot
fig.show()
scatter plot

5 . Bubble Plot

A bubble plot is a scatter plot with bubbles (color-filled circles). Bubbles have various sizes dependent on another variable in the data. It can be created using the scatter() method of plotly.express.

import plotly.express as pxdf = px.data.iris()# plotting the bubble chart
fig = px.scatter(df, x="species", y="petal_width",
size="petal_length", color="species")
# showing the plot
fig.show()
bubble plot

6. Pie Charts

A Pie Chart is a circular statistical plot that can display only one series of data. The area of the chart is the total percentage of the given data. The area of slices of the pie represents the percentage of the parts of the data.

import plotly.express as pxdf = px.data.tips()# plotting the pie chart
fig = px.pie(df, values="total_bill", names="day")
# showing the plot
fig.show()
Pie Chart

Thanks for reading. Hope it was useful.

Happy learning.

--

--