0% found this document useful (0 votes)
12 views4 pages

Matplotlib Subplots and Pandas Plotting

Uploaded by

deepshree sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Matplotlib Subplots and Pandas Plotting

Uploaded by

deepshree sharma
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

keyboard_arrow_down Unit 3 Sub Plots _Matplotlib _DG tutorials.

ipynb

import [Link] as plt

fig, axs = [Link](2, 2, figsize=(8,6)) # 2x2 grid of subplots

axs[0,0].plot([1,2,3],[4,5,6])
axs[0,0].set_title("Plot 1")

axs[0,1].plot([1,2,3],[6,5,4])
axs[0,1].set_title("Plot 2")

axs[1,0].plot([1,2,3],[1,2,1])
axs[1,0].set_title("Plot 3")

axs[1,1].plot([1,2,3],[3,3,3])
axs[1,1].set_title("Plot 4")

plt.tight_layout() # Adjust spacing automatically


[Link]()

import [Link] as plt

fig, axs = [Link](3, 3, figsize=(8,6)) # 3x2 grid of subplots

axs[0,0].plot([1,2,3],[4,5,6])
axs[0,0].set_title("Plot 1")

axs[0,1].plot([1,2,3],[6,5,4])
axs[0,1].set_title("Plot 2")

axs[1,0].plot([1,2,3],[1,2,1])
axs[1,0].set_title("Plot 3")

axs[0,2].plot([1,2,3],[6,5,4])
axs[0,2].set_title("Plot DG")

axs[1,1].plot([1,2,3],[3,3,3])
axs[1,1].set_title("Plot 4")

axs[2,0].plot([1,2,3],[5,5,5]) # Placeholder for Plot 5


axs[2,0].set_title("Plot 5")

plt.tight_layout() # Adjust spacing automatically


[Link]()
[Link]([1,2,3,4], [1,4,2,3], color='green', linestyle='--', marker='o')
[Link]()

#color → 'red', 'green', 'blue', or hex codes #FF0000.

#linestyle → '-', '--', '-.', ':'.

#marker → 'o', 's', '^', '*', etc.

[Link]([1,2,3], [4,5,6], label='Line A')


[Link]([1,2,3], [6,5,4], label='Line B')

[Link]("Sample Plot")
[Link]("X-axis")
[Link]("Y-axis")

[Link]([1,2,3], ['One','Two','Three']) # Custom tick labels


[Link]([4,5,6])

[Link]() # Show line labels


[Link]()
xlabel / ylabel → names of axes

xticks / yticks → set positions and labels of ticks

legend → describes the lines

keyboard_arrow_down Plotting Functions in Pandas

import pandas as pd

data = [Link]({
'Month': ['Jan','Feb','Mar','Apr'],
'Sales': [200, 300, 250, 400],
'Profit': [50, 70, 60, 90]
})

# Line plot
[Link](x='Month', y='Sales', kind='line', marker='o', color='blue', title='Monthly Sales')

# Bar plot
[Link](x='Month', y='Profit', kind='bar', color='orange', title='Monthly Profit')

[Link]()

Pandas DataFrames can plot directly, internally using Matplotlib.

kind → type of plot: 'line', 'bar', 'scatter', 'hist', etc.

Pandas handles the figure and axes automatically.

Topic Key Points Example

Figures & Subplots fig, ax = [Link]() Multiple plots in one figure

Spacing plt.tight_layout() Avoid overlapping labels

Colors/Markers/Line color , marker , linestyle Customize lines and points


Ticks & Labels xlabel , ylabel , xticks , yticks Customize axes

Legends [Link]() Label multiple lines


Title [Link]() Add plot title

Pandas Plotting [Link](x=..., y=..., kind=...) Quick plotting from DataFrame

You might also like