๐ Interactive Plots with Plotly
Plotly allows you to create interactive charts that you can zoom, pan, and hover over.
Mastering this concept will significantly boost your Python data science skills!
๐ป Code Example:
import plotly.graph_objects as go from plotly.subplots import make_subplots # 1. Multi-panel interactive dashboard fig = make_subplots( rows=2, cols=2, subplot_titles=("Monthly Revenue", "Course Distribution", "User Growth", "Score Range"), specs=[[{"type": "scatter"}, {"type": "pie"}], [{"type": "bar"}, {"type": "box"}]], ) months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"] revenue = [45000, 52000, 48000, 61000, 75000, 89000] # Line + markers fig.add_trace(go.Scatter( x=months, y=revenue, mode="lines+markers", name="Revenue (โน)", line=dict(color="#3498db", width=3), marker=dict(size=8), ), row=1, col=1) # Pie chart fig.add_trace(go.Pie( labels=["Python", "AI", "DevOps", "Testing"], values=[45, 30, 15, 10], hole=0.4, name="Courses", ), row=1, col=2) # Bar chart users = [120, 185, 210, 275, 340, 420] fig.add_trace(go.Bar( x=months, y=users, name="New Users", marker_color="#2ecc71", ), row=2, col=1) # Box plot import numpy as np np.random.seed(42) for course, color in zip(["Python", "AI", "DevOps"], ["royalblue", "tomato", "gold"]): scores = np.random.randint(55, 100, 40) fig.add_trace(go.Box(y=scores, name=course, marker_color=color), row=2, col=2) fig.update_layout( title_text="Pynfinity Platform Dashboard", height=600, showlegend=False, ) fig.show()
Keep exploring and happy coding! ๐ป