Subplots

Python में Plotly के साथ Data Visualization परिचय

Alex Scriven

Data Scientist

Subplots क्या हैं?

 

  • Subplots: ग्रिड में रखे गए 'mini-plots'

$$

  • अलग-अलग प्लॉट टाइप्स (एक ही डेटा) या अलग डेटा सबसेट दिखाएँ

 

Subplots का खाका

Python में Plotly के साथ Data Visualization परिचय

Traces की याद दिलाहट

 

  • Plotly figures में traces की सूची होती है - डेटा और टाइप

  • fig.data[0], fig.data[1] से एक्सेस करें

    • .add_trace() से subplots में जोड़ें

$$

px_fig = px.scatter(df...)
print(px_fig)
Figure({'data': [trace1], 'layout': {...}})
Python में Plotly के साथ Data Visualization परिचय

1x2 subplot बनाना

import plotly.express as px
from plotly.subplots import make_subplots

# Create a subplot grid
fig = make_subplots(rows=2, cols=1)

# Create plotly express figures hist = px.histogram(revenues, x='Revenue') box = px.box(revenues, x='Revenue')
# Extract traces and add to subplots fig.add_trace(hist.data[0], row=1, col=1) fig.add_trace(box.data[0], row=2, col=1) fig.show()

 

एक फ़ाइनेंस subplot

Python में Plotly के साथ Data Visualization परिचय

Subplots को कस्टमाइज़ करना

 

  • कोई ओवरऑल प्लॉट शीर्षक नहीं
  • कोई subplot शीर्षक नहीं

$$

$$

$$

  • ✨ इसे प्रस्तुति-योग्य बनाएँ

 

सिंपल फ़ाइनेंस subplot

Python में Plotly के साथ Data Visualization परिचय

Subplot शीर्षक

from plotly.subplots import make_subplots

fig = make_subplots(rows=2, cols=1,
    subplot_titles=[
    'Histogram of company revenues', 
    'Box plot of company revenues'])

## Add in traces (fig.add_trace())
fig.update_layout({'title': {'text': 'Plots of company revenues', 'x': 0.5, 'y': 0.9}}) fig.show()

Subplot शीर्षक ठीक किए

और विकल्प documentation में

Python में Plotly के साथ Data Visualization परिचय

Stacked subplots

$$

fig = make_subplots(rows=3, cols=1, 
  subplot_titles=['Adelie Penguins'
  , 'Gentoo Penguins', 'Chinstrap Penguins'])

row_num = 1 for species in ['Adelie', 'Gentoo', 'Chinstrap']: # Filter data for this species df = penguins[penguins['Species'] == species]
scatter = px.scatter(df, x='Culmen Length (mm)' , y='Culmen Depth (mm)') # Add the trace to the subplot fig.add_trace(scatter.data[0] , row=row_num, col=1) row_num +=1

Penguins subplots stacked

Python में Plotly के साथ Data Visualization परिचय

Shared axes वाले subplots

 

  • x-axis को 'shared' बनाना:
fig = make_subplots(
    rows=3, cols=1
    , shared_xaxes=True)

shared x-axis पेंगुइन subplots

Python में Plotly के साथ Data Visualization परिचय

अभ्यास करते हैं!

Python में Plotly के साथ Data Visualization परिचय

Preparing Video For Download...