import plotly
print(plotly.__version__) # Should be 5.x or above
6.0.0
Benedict Thekkel
To get started with Plotly in Jupyter Labs, you need to install the following:
To render Plotly figures within JupyterLab, you need to install the following extensions:
Ensure you have Plotly version 5.x or above for the latest features.
import plotly.express as px
import numpy as np
import pandas as pd
# Sample Data
x = np.linspace(0, 10, 100)
y = np.sin(x)
df = pd.DataFrame({'x': x, 'y': y})
# Line Plot
fig = px.line(df, x='x', y='y', title='Sine Wave')
fig.show()
### **4.2. Scatter Plot**
```python
fig = px.scatter(df, x='x', y='y', title='Scatter Plot of Sine Wave')
fig.show()
import plotly.express as px
import numpy as np
import pandas as pd
import plotly.offline as pyo
from IPython.display import HTML, display
# Sample Data
x = np.linspace(0, 10, 100)
y = np.sin(x)
df = pd.DataFrame({'x': x, 'y': y})
# Turn off the menu bar
config = {
'displayModeBar': False # Disable the mode bar (menu bar)
}
# Line Plot
fig = px.line(df, x='x', y='y', title='Sine Wave')
# fig.show(config=config)
fig_html = fig.to_html(full_html=False, config=config)
display(HTML(fig_html))
fig = px.scatter(df, x='x', y='y', title='Scatter Plot of Sine Wave')
# fig.show(config=config)
fig_html = fig.to_html(full_html=False, config=config)
display(HTML(fig_html))
data = {'Fruits': ['Apple', 'Banana', 'Cherry', 'Date'],
'Quantity': [10, 20, 15, 5]}
df = pd.DataFrame(data)
fig = px.bar(df, x='Fruits', y='Quantity', title='Fruit Quantity')
fig_html = fig.to_html(full_html=False, config=config)
display(HTML(fig_html))
fig = px.histogram(df, x='Quantity', title='Histogram of Quantity')
fig_html = fig.to_html(full_html=False, config=config)
display(HTML(fig_html))
fig = px.pie(df, names='Fruits', values='Quantity', title='Fruit Distribution')
fig_html = fig.to_html(full_html=False, config=config)
display(HTML(fig_html))