Plot with Plotly

Dorjey Sherpa
Analytics Vidhya
Published in
2 min readNov 18, 2020

--

Plotly logo from Plotly.com

Regardless of what we are learning or doing, we start with the basics, the foundation, the core. Then we learn more tools and techniques, skills and shortcuts — we learn to do things better and make it more “advanced”.

Today, we will be looking at another tool to “advance” our data visualization skills.

What is plotly? Why should we use it?

Plot is a free and open source graphing library that makes amazing interactive graphs. It does everything that Seaborn and Matplotlib does, but makes it more fun for the viewer.

Data: All the articles and author data are extracted directly from Towards Data Science from 1/1/2020 until 10/31/2020.

How to get started?

In order to visualize with plotly, you need to have a good understanding of Matplotlib and Seaborn.

How to import :

import plotly.graph_objects as go

You will also see: import plotly.express as px. This wrapper allows for simpler syntax but at the cost of control over the graph. plotly.graph_objects has a wider control over what you are creating. Additionally plotly.express is still fairly new with a few bugs.

top_ten_authors = df["author"].value_counts().keys().tolist()[:10] #selecting top 10number_published = df["author"].value_counts().values.tolist() # num of pub correspoding to the top 10 authorstrace = go.Pie(labels = top_ten_authors, #assigning label
values = number_published, #assigning values
marker = {'line': {'color': 'white', 'width': 1}}, # generating the lines
#hoverinfo="value"
)
data = [trace]layout = go.Layout(title="Top 10 People With Most Publications in 2020");
pie_fig = go.Figure(data=data, layout = layout);

pie_fig.show()
x = df['author'][:25] 
trace = go.Bar(x = x ,
y=df['claps'],
text = df["reading_time"])
data=[trace]
#defining layout
layout = go.Layout(title='Claps Vs Authors Scatter Plot',xaxis=dict(title='Authors'),yaxis=dict(title='Claps'),hovermode='closest')
#defining figure and plotting

bar_fig = go.Figure(data=data,layout=layout)
bar_fig.show()

Being able to interact with the graphs is great for the viewer. They get to explore further into the data by zooming in and out and panning across the visualization.

--

--