FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
in Python Programming by Goeduhub's Expert (3.1k points)

Plotly Library in Python for interactive graphs. What is Plotly in Python? How do you import Plotly in Python? Is Plotly better than Matplotlib? Can I use Plotly for free?

1 Answer

0 like 0 dislike
by Goeduhub's Expert (3.1k points)
edited by
Best answer

Why did we need Plotly plotting library in python.

we have already Matpoltlib, Seaborn plotting libraries in pyhton.

The answer is simple matplotlib and seaborn can only plot static graphs. Static plots are like simple non-interactive images.

What is Plotly in Python?


In simple terms plotly is a pyhton package to plot interactive plots. Interactive plots mean you can zoom and drag the plot, and can see the data at the point of the cursor.

Official Documentation of plotly library (click here) to follow the recent changes in the library.

How do you import Plotly in Python?

Installation of plotly 

pip install plotly==4.8.1
 conda install -c plotly plotly=4.8.1

Other requirements we will also use Cufflinks, which works as a connector between the Pandas library and Plotly. With help of cufflinks we can plot interactive plots with pandas dataframe.

pip install cufflinks

Chart Studio

When you click on the  plots/images given below, you can see the plots/images/graphs in the browser (in online mode).Actually I have given a link to their web browser here, so you can see that in a browser. 

Chart Studio Enterprise, it creates an interactive shareable web view of your plot.

plotly chart studio: Chart Studio provides a web-service for hosting graphs! Create a free account to get started. Graphs are saved inside your online Chart Studio account and you control the privacy. Public hosting is free, for private hosting, check out our paid plans.

To use chart studio first we have to install it in plotly.

pip install chart-studio==1.0.0
conda install -c plotly chart-studio=1.0.0

Getting Started

Importing Required libraries 

#importing required libraries 

import pandas as pd

import numpy as np

%matplotlib inline

#creating plotly offline mode

from plotly.offline import download_plotlyjs, 

init_notebook_mode, plot, iplot

#connecting jupyter notebook with javascript


#importing offline cufflinks library

import cufflinks as cf



What is Plotly offline?

In the above code pandas and numpy is used for data manipulation.Next, we have imported the offline versions of the Plotly modules that we will be using in this article.

Plotly itself is a technical computing company headquartered in Montreal, Canada, that develops online data analytics and visualization tools. 

Can I use Plotly for free?

The Python library is free to use, and we can make unlimited charts in offline mode plus up to 25 charts in online mode to share with the world (Chart Studio).

Since Plotly plots are interactive, they make use of JavaScript behind the scenes.So, we connected java script with jupyter notebook in next step.After that we imported cufflinks offline library.

#reading tips datasets 

import seaborn as sns

dataset = sns.load_dataset('tips')



datasets tips 

#plotting simple interactive plot 

dataset2 = dataset[["total_bill", "tip"]]





In the output above, we have seen how interactive map works.You must have seen that I have made a red circle in the right corner below.This is a link to this Chart/Graph that you can open online in any default browser.

If you replace the iplot with plot here, then you will get simple plots as matplotlib and seaborn.

Click on the Image to see the image/plot in a browser (in online mode).

Plotting with use of Pandas Aggregate functions (Mean, Median,Count, range , average etc.....)

#plotting with pandas aggregate functions 




Click on this plot/Image to see the plot/image in a browser online mode.

In this way, we can also plot bar plot, scatter plot, Hist plot, spread plot. 

What we have to do to change the plot type, we just have to tell the plot type in kind parameter in the plot/iplot function.

When we should use which type of plot (scatter, bar , line etc...) it depends on the our data.(Meaning, which plot will visualize the data properly we will use it).

3D plots 

Finally, in addition to 2D plots, you can also create 3-D interactive plots using Plotly library. To plot 3-D plot here we just passed surface in kind parameter of iplot function.

#3-D plotting in plotly
dataset2 = dataset[["total_bill", "tip", "size"]] data = dataset2.iplot(kind='surface', colorscale='rdylbu')


3d image

A simple use case (plotting coronavirus cases)

Here is a simple use case to understand how we can use this library in  real life. The datasets used here is a simple datasets you can create it using excel  (cases with dates).

#importing libraries 

import pandas as pd

import numpy as np

%matplotlib inline

from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot


import cufflinks as cf


#reading latest coronavirus cases 

confirmed_cases= pd.read_csv("Book1.csv")



#plotting simple line 



line corona gif

#plotting bar plot 



bar plot cases

Python Tutorial 

Machine Learning Tutorial 

AI Tutorial

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

Related questions

0 like 0 dislike
2 answers 3.6k views
0 like 0 dislike
1 answer 1.1k views
asked May 14, 2020 in Python Programming by Nisha Goeduhub's Expert (3.1k points)
0 like 0 dislike
2 answers 1.5k views
asked Sep 14, 2020 in Python Programming by Nisha Goeduhub's Expert (3.1k points)

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs


About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © Social::   |  | 


Free Online Directory