*How to Install and Use Plotly in Jupyter Notebook | Interactive Data Visualization*
*Description:*
Want to create *interactive and stunning visualizations* in *Jupyter Notebook**? 📊✨ **Plotly* is a powerful Python library that lets you build *dynamic, interactive charts and graphs* effortlessly. In this tutorial, we’ll show you how to *install Plotly in Jupyter Notebook* and create your first interactive plots! 🚀
By the end of this tutorial, you'll know how to *install, import, and use Plotly* to visualize datasets with interactive features.
---
🔹 *What You’ll Learn in This Video:*
✅ How to *install Plotly using pip* in Jupyter Notebook
✅ How to verify if Plotly is installed correctly
✅ How to create *interactive plots* using Plotly
✅ How to use Plotly with *pandas and Jupyter Notebook*
✅ Fixing common *installation errors*
---
*🚀 Step-by-Step Guide to Installing and Using Plotly in Jupyter Notebook*
#### *1️⃣ Open Jupyter Notebook*
Launch Jupyter Notebook by running the following command in your terminal or command prompt:
```bash
jupyter notebook
```
---
#### *2️⃣ Install Plotly Using pip in Jupyter Notebook*
In a new Jupyter Notebook cell, run:
```python
!pip install plotly
```
🔹 This will install *Plotly* and all its dependencies.
If you're using **Anaconda**, install Plotly with:
```python
!conda install -c plotly plotly -y
```
---
#### *3️⃣ Verify Plotly Installation*
After installation, check if Plotly is installed correctly by running:
```python
import plotly
print(plotly.__version__) # This will print the installed Plotly version
```
✅ If no errors appear, Plotly is installed successfully!
---
#### *4️⃣ Import Plotly and Create Your First Plot*
```python
import plotly.express as px
Sample Data (Built-in Dataset)
df = px.data.gapminder().query("year == 2007")
Create an Interactive Scatter Plot
fig = px.scatter(df, x="gdpPercap", y="lifeExp", size="pop", color="continent",
hover_name="country", log_x=True, size_max=60)
fig.show()
```
✨ *Congratulations!* You’ve just created your first *interactive* Plotly chart in Jupyter Notebook! 🎉
---
🔹 *More Plotly Chart Examples*
📌 *Line Chart:*
```python
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3, 4, 5], y=[10, 20, 15, 25, 30], mode='lines+markers', name='Line Chart'))
fig.show()
```
📌 *Bar Chart:*
```python
fig = px.bar(df, x="continent", y="pop", color="continent", title="Population by Continent")
fig.show()
```
📌 *Pie Chart:*
```python
fig = px.pie(df, names="continent", values="pop", title="Population Distribution by Continent")
fig.show()
```
📌 *3D Scatter Plot:*
```python
fig = px.scatter_3d(df, x="gdpPercap", y="lifeExp", z="pop", color="continent", hover_name="country")
fig.show()
```
---
🔹 *Fixing Common Errors*
*Error: "ModuleNotFoundError: No module named 'plotly'"*
🔹 Run the following command in a Jupyter Notebook cell:
```python
!pip install plotly
```
*Plot Not Displaying in Jupyter Notebook?*
🔹 Add this magic command at the beginning of your notebook:
```python
import plotly.io as pio
pio.renderers.default = "notebook"
```
Or change the renderer to:
```python
pio.renderers.default = "iframe"
```
*Using Plotly in Offline Mode?*
🔹 Add the following code at the start:
```python
import plotly.offline as pyo
pyo.init_notebook_mode(connected=True)
```
---
*📌 Useful Links:*
🔗 Plotly Documentation: [https://plotly.com/python/](https://plotly.com/python/)
🔗 Jupyter Notebook Guide: [https://jupyter.org/](https://jupyter.org/)
🚀 *Have Questions?* Drop a comment below! If this tutorial helped you, *LIKE* 👍 this video, *SUBSCRIBE* 🔔 for more Python and Jupyter Notebook tutorials, and *SHARE* with your friends!
📌 *Hashtags:*
#Plotly #JupyterNotebook #Python #DataVisualization #InteractiveCharts #MachineLearning #DataScience #PythonPlots #PlotlyGraphs #LearnPython
Информация по комментариям в разработке