0% found this document useful (0 votes)
26 views77 pages

Matplotlib Data Visualization Notebook

Matplotlib is a popular Python library for creating static, animated, and interactive visualizations with a simple and customizable interface. It supports various plot types and is commonly used for exploratory data analysis, statistical visualization, and machine learning performance visualization. The document includes practical examples of plotting data using Matplotlib, including line plots, scatter plots, and customization options.

Uploaded by

Akshay Yeole
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)
26 views77 pages

Matplotlib Data Visualization Notebook

Matplotlib is a popular Python library for creating static, animated, and interactive visualizations with a simple and customizable interface. It supports various plot types and is commonly used for exploratory data analysis, statistical visualization, and machine learning performance visualization. The document includes practical examples of plotting data using Matplotlib, including line plots, scatter plots, and customization options.

Uploaded by

Akshay Yeole
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

2/12/25, 3:38 PM 15-Matplotlib

📊 Introduction to Matplotlib
Matplotlib is a widely used data visualization library in Python that enables the creation
of static, animated, and interactive visualizations. It provides an easy-to-use interface
for plotting data and is highly customizable.

🔹 Why Use Matplotlib?


Simple and intuitive syntax.
Highly customizable for professional-quality plots.
Supports multiple plot types (line, bar, scatter, histogram, etc.).
Works seamlessly with NumPy and Pandas.
Enables interactive and animated visualizations.

🔹 Common Use Cases


✔ Exploratory Data Analysis (EDA)
✔ Statistical Data Visualization
✔ Machine Learning Model Performance Visualization
✔ Business and Financial Data Presentation
📌 Let's dive into Matplotlib with hands-on practice! 🚀

Types of Data
Numerical Data
Categorical Data

In [78]: # import the library


import numpy as np
import pandas as pd
import [Link] as plt
import seaborn as sns

[Link]('default')

2D Line plot

[Link] 1/77
2/12/25, 3:38 PM 15-Matplotlib

Bivariate Analysis
categorical -> numerical and numerical -> numerical
Use case - Time series data

In [79]: # plotting a simple function


price = [48000,54000,57000,49000,47000,45000]
year = [2015,2016,2017,2018,2019,2020]

[Link](year,price)

Out[79]: [<[Link].Line2D at 0x1a0f3125c10>]

[Link] 2/77
2/12/25, 3:38 PM 15-Matplotlib

In [80]: # from a pandas dataframe


batsman = pd.read_csv('[Link]')
batsman

[Link](batsman['index'],batsman['V Kohli'])

Out[80]: [<[Link].Line2D at 0x1a0f3010b10>]

In [81]: # plotting multiple plots


[Link](batsman['index'],batsman['V Kohli'])
[Link](batsman['index'],batsman['RG Sharma'])

Out[81]: [<[Link].Line2D at 0x1a0f327f7d0>]

[Link] 3/77
2/12/25, 3:38 PM 15-Matplotlib

In [82]: # labels title


[Link](batsman['index'],batsman['V Kohli'])
[Link](batsman['index'],batsman['RG Sharma'])

[Link]('Rohit Sharma Vs Virat Kohli Career Comparison')


[Link]('Season')
[Link]('Runs Scored')

Out[82]: Text(0, 0.5, 'Runs Scored')

[Link] 4/77
2/12/25, 3:38 PM 15-Matplotlib

In [83]: # colors(hex) and line(width and style) and marker(size)


[Link](batsman['index'],batsman['V Kohli'],color='#D9F10F')
[Link](batsman['index'],batsman['RG Sharma'],color='#FC00D6')

[Link]('Rohit Sharma Vs Virat Kohli Career Comparison')


[Link]('Season')
[Link]('Runs Scored')

Out[83]: Text(0, 0.5, 'Runs Scored')

[Link] 5/77
2/12/25, 3:38 PM 15-Matplotlib

In [84]: [Link](batsman['index'],batsman['V Kohli'],color='#D9F10F',linestyle='solid',l


[Link](batsman['index'],batsman['RG Sharma'],color='#FC00D6',linestyle='dashdo

[Link]('Rohit Sharma Vs Virat Kohli Career Comparison')


[Link]('Season')
[Link]('Runs Scored')

Out[84]: Text(0, 0.5, 'Runs Scored')

[Link] 6/77
2/12/25, 3:38 PM 15-Matplotlib

In [85]: [Link](batsman['index'],batsman['V Kohli'],color='#D9F10F',linestyle='solid',l


[Link](batsman['index'],batsman['RG Sharma'],color='#FC00D6',linestyle='dashdo

[Link]('Rohit Sharma Vs Virat Kohli Career Comparison')


[Link]('Season')
[Link]('Runs Scored')

Out[85]: Text(0, 0.5, 'Runs Scored')

[Link] 7/77
2/12/25, 3:38 PM 15-Matplotlib

In [86]: # legend -> location


[Link](batsman['index'],batsman['V Kohli'],color='#D9F10F',linestyle='solid',l
[Link](batsman['index'],batsman['RG Sharma'],color='#FC00D6',linestyle='dashdo

[Link]('Rohit Sharma Vs Virat Kohli Career Comparison')


[Link]('Season')
[Link]('Runs Scored')

[Link](loc='upper right')

Out[86]: <[Link] at 0x1a0f3609c90>

[Link] 8/77
2/12/25, 3:38 PM 15-Matplotlib

In [87]: # limiting axes


price = [48000,54000,57000,49000,47000,45000,4500000]
year = [2015,2016,2017,2018,2019,2020,2021]

[Link](year,price)
[Link](0,75000)
[Link](2017,2019)

Out[87]: (2017.0, 2019.0)

[Link] 9/77
2/12/25, 3:38 PM 15-Matplotlib

In [88]: # grid
[Link](batsman['index'],batsman['V Kohli'],color='#D9F10F',linestyle='solid',l
[Link](batsman['index'],batsman['RG Sharma'],color='#FC00D6',linestyle='dashdo

[Link]('Rohit Sharma Vs Virat Kohli Career Comparison')


[Link]('Season')
[Link]('Runs Scored')

[Link]()

[Link] 10/77
2/12/25, 3:38 PM 15-Matplotlib

In [89]: # show
[Link](batsman['index'],batsman['V Kohli'],color='#D9F10F',linestyle='solid',l
[Link](batsman['index'],batsman['RG Sharma'],color='#FC00D6',linestyle='dashdo

[Link]('Rohit Sharma Vs Virat Kohli Career Comparison')


[Link]('Season')
[Link]('Runs Scored')

[Link]()

[Link]()

[Link] 11/77
2/12/25, 3:38 PM 15-Matplotlib

Scatter Plots

Bivariate Analysis
numerical vs numerical
Use case - Finding correlation

In [90]: # [Link] simple function


x = [Link](-10,10,50)

y = 10*x + 3 + [Link](0,300,50)
y

[Link] 12/77
2/12/25, 3:38 PM 15-Matplotlib

Out[90]: array([115. , 188.08163265, -40.83673469, -35.75510204,


-36.67346939, 146.40816327, 66.48979592, 5.57142857,
229.65306122, 98.73469388, 8.81632653, 173.89795918,
117.97959184, 226.06122449, 161.14285714, 36.2244898 ,
189.30612245, 182.3877551 , 124.46938776, 19.55102041,
156.63265306, 146.71428571, 97.79591837, 245.87755102,
234.95918367, 214.04081633, 189.12244898, 307.20408163,
17.28571429, 233.36734694, 203.44897959, 56.53061224,
90.6122449 , 194.69387755, 231.7755102 , 240.85714286,
68.93877551, 121.02040816, 349.10204082, 115.18367347,
147.26530612, 358.34693878, 168.42857143, 228.51020408,
380.59183673, 296.67346939, 144.75510204, 232.83673469,
350.91836735, 313. ])

In [91]: [Link](x,y)

Out[91]: <[Link] at 0x1a0f366d750>

In [92]: # [Link] on pandas data


df = pd.read_csv('[Link]')
df = [Link](50)
df

[Link] 13/77
2/12/25, 3:38 PM 15-Matplotlib

Out[92]: batter runs avg strike_rate

0 V Kohli 6634 36.251366 125.977972

1 S Dhawan 6244 34.882682 122.840842

2 DA Warner 5883 41.429577 136.401577

3 RG Sharma 5881 30.314433 126.964594

4 SK Raina 5536 32.374269 132.535312

5 AB de Villiers 5181 39.853846 148.580442

6 CH Gayle 4997 39.658730 142.121729

7 MS Dhoni 4978 39.196850 130.931089

8 RV Uthappa 4954 27.522222 126.152279

9 KD Karthik 4377 26.852761 129.267572

10 G Gambhir 4217 31.007353 119.665153

11 AT Rayudu 4190 28.896552 124.148148

12 AM Rahane 4074 30.863636 117.575758

13 KL Rahul 3895 46.927711 132.799182

14 SR Watson 3880 30.793651 134.163209

15 MK Pandey 3657 29.731707 117.739858

16 SV Samson 3526 29.140496 132.407060

17 KA Pollard 3437 28.404959 140.457703

18 F du Plessis 3403 34.373737 127.167414

19 YK Pathan 3222 29.290909 138.046272

20 BB McCullum 2882 27.711538 126.848592

21 RR Pant 2851 34.768293 142.550000

22 PA Patel 2848 22.603175 116.625717

23 JC Buttler 2832 39.333333 144.859335

24 SS Iyer 2780 31.235955 121.132898

25 Q de Kock 2767 31.804598 130.951254

26 Yuvraj Singh 2754 24.810811 124.784776

27 V Sehwag 2728 27.555556 148.827059

28 SA Yadav 2644 29.707865 134.009123

29 M Vijay 2619 25.930693 118.614130

30 RA Jadeja 2502 26.617021 122.108346

31 SPD Smith 2495 34.652778 124.812406

32 SE Marsh 2489 39.507937 130.109775

[Link] 14/77
2/12/25, 3:38 PM 15-Matplotlib

batter runs avg strike_rate

33 DA Miller 2455 36.102941 133.569097

34 JH Kallis 2427 28.552941 105.936272

35 WP Saha 2427 25.281250 124.397745

36 DR Smith 2385 28.392857 132.279534

37 MA Agarwal 2335 22.669903 129.506378

38 SR Tendulkar 2334 33.826087 114.187867

39 GJ Maxwell 2320 25.494505 147.676639

40 N Rana 2181 27.961538 130.053667

41 R Dravid 2174 28.233766 113.347237

42 KS Williamson 2105 36.293103 123.315759

43 AJ Finch 2092 24.904762 123.349057

44 AC Gilchrist 2069 27.223684 133.054662

45 AD Russell 2039 29.985294 168.234323

46 JP Duminy 2029 39.784314 120.773810

47 MEK Hussey 1977 38.764706 119.963592

48 HH Pandya 1972 29.878788 140.256046

49 Shubman Gill 1900 32.203390 122.186495

In [93]: [Link](df['avg'],df['strike_rate'],color='red',marker='+')
[Link]('Avg and SR analysis of Top 50 Batsman')
[Link]('Average')
[Link]('SR')

Out[93]: Text(0, 0.5, 'SR')

[Link] 15/77
2/12/25, 3:38 PM 15-Matplotlib

In [94]: # size
tips = sns.load_dataset('tips')

# slower
[Link](tips['total_bill'],tips['tip'],s=tips['size']*20)

Out[94]: <[Link] at 0x1a0f32ee910>

[Link] 16/77
2/12/25, 3:38 PM 15-Matplotlib

In [95]: # scatterplot using [Link]


# faster
[Link](tips['total_bill'],tips['tip'],'o')

Out[95]: [<[Link].Line2D at 0x1a0f3d65850>]

Bar chart

[Link] 17/77
2/12/25, 3:38 PM 15-Matplotlib

Bivariate Analysis
Numerical vs Categorical
Use case - Aggregate analysis of groups

In [96]: # simple bar chart


children = [10,20,40,10,30]
colors = ['red','blue','green','yellow','pink']

[Link](colors,children,color='black')

Out[96]: <BarContainer object of 5 artists>

[Link] 18/77
2/12/25, 3:38 PM 15-Matplotlib

In [97]: # horizontal bar chart


[Link](colors,children,color='black')

Out[97]: <BarContainer object of 5 artists>

In [98]: # color and label


df = pd.read_csv('batsman_season_record.csv')
df

[Link] 19/77
2/12/25, 3:38 PM 15-Matplotlib

Out[98]: batsman 2015 2016 2017

0 AB de Villiers 513 687 216

1 DA Warner 562 848 641

2 MS Dhoni 372 284 290

3 RG Sharma 482 489 333

4 V Kohli 505 973 308

In [99]: [Link]([Link]([Link][0]) - 0.2,df['2015'],width=0.2,color='yellow')


[Link]([Link]([Link][0]),df['2016'],width=0.2,color='red')
[Link]([Link]([Link][0]) + 0.2,df['2017'],width=0.2,color='blue')

[Link]([Link]([Link][0]), df['batsman'])

[Link]()

In [100… [Link]([Link][0])

Out[100… array([0, 1, 2, 3, 4])

In [101… # a problem
children = [10,20,40,10,30]
colors = ['red red red red red red','blue blue blue blue','green green green gre

[Link](colors,children,color='black')
[Link](rotation='vertical')

[Link] 20/77
2/12/25, 3:38 PM 15-Matplotlib

Out[101… ([0, 1, 2, 3, 4],


[Text(0, 0, 'red red red red red red'),
Text(1, 0, 'blue blue blue blue'),
Text(2, 0, 'green green green green green'),
Text(3, 0, 'yellow yellow yellow yellow '),
Text(4, 0, 'pink pinkpinkpink')])

In [102… # Stacked Bar chart


[Link](df['batsman'],df['2017'],label='2017')
[Link](df['batsman'],df['2016'],bottom=df['2017'],label='2016')
[Link](df['batsman'],df['2015'],bottom=(df['2016'] + df['2017']),label='2015')

[Link]()
[Link]()

[Link] 21/77
2/12/25, 3:38 PM 15-Matplotlib

Histogram

Univariate Analysis
Numerical col
Use case - Frequency Count

In [103… # simple data

data = [32,45,56,10,15,27,61]

[Link](data,bins=[10,25,40,55,70])

[Link] 22/77
2/12/25, 3:38 PM 15-Matplotlib

Out[103… (array([2., 2., 1., 2.]),


array([10., 25., 40., 55., 70.]),
<BarContainer object of 4 artists>)

In [104… # on some data


df = pd.read_csv('[Link]')
df

Out[104… match_id batsman_runs

0 12 62

1 17 28

2 20 64

3 27 0

4 30 10

... ... ...

136 624 75

137 626 113

138 632 54

139 633 0

140 636 54

141 rows × 2 columns

In [105… [Link](df['batsman_runs'],bins=[0,10,20,30,40,50,60,70,80,90,100,110,120])
[Link]()

[Link] 23/77
2/12/25, 3:38 PM 15-Matplotlib

In [106… # logarithmic scale


arr = [Link]('[Link]')
[Link](arr,bins=[10,20,30,40,50,60,70],log=True)
[Link]()

Pie Chart

[Link] 24/77
2/12/25, 3:38 PM 15-Matplotlib

Univariate/Bivariate Analysis
Categorical vs numerical
Use case - To find contibution on a standard scale

In [107… # simple data


data = [23,45,100,20,49]
subjects = ['eng','science','maths','sst','hindi']
[Link](data,labels=subjects)

[Link]()

In [108… # dataset
df = pd.read_csv('[Link]')
df

[Link] 25/77
2/12/25, 3:38 PM 15-Matplotlib

Out[108… batsman batsman_runs

0 AB de Villiers 31

1 CH Gayle 175

2 R Rampaul 0

3 SS Tiwary 2

4 TM Dilshan 33

5 V Kohli 11

In [109… [Link](df['batsman_runs'],labels=df['batsman'],autopct='%0.1f%%')
[Link]()

In [110… # percentage and colors


[Link](df['batsman_runs'],labels=df['batsman'],autopct='%0.1f%%',colors=['blue'
[Link]()

[Link] 26/77
2/12/25, 3:38 PM 15-Matplotlib

In [111… # explode shadow


[Link](df['batsman_runs'],labels=df['batsman'],autopct='%0.1f%%',explode=[0.3,0
[Link]()

Changing styles
In [112… [Link]

[Link] 27/77
2/12/25, 3:38 PM 15-Matplotlib

Out[112… ['Solarize_Light2',
'_classic_test_patch',
'_mpl-gallery',
'_mpl-gallery-nogrid',
'bmh',
'classic',
'dark_background',
'fast',
'fivethirtyeight',
'ggplot',
'grayscale',
'seaborn-v0_8',
'seaborn-v0_8-bright',
'seaborn-v0_8-colorblind',
'seaborn-v0_8-dark',
'seaborn-v0_8-dark-palette',
'seaborn-v0_8-darkgrid',
'seaborn-v0_8-deep',
'seaborn-v0_8-muted',
'seaborn-v0_8-notebook',
'seaborn-v0_8-paper',
'seaborn-v0_8-pastel',
'seaborn-v0_8-poster',
'seaborn-v0_8-talk',
'seaborn-v0_8-ticks',
'seaborn-v0_8-white',
'seaborn-v0_8-whitegrid',
'tableau-colorblind10']

In [113… [Link]('dark_background')

In [114… arr = [Link]('[Link]')


[Link](arr,bins=[10,20,30,40,50,60,70],log=True)
[Link]()

[Link] 28/77
2/12/25, 3:38 PM 15-Matplotlib

Save figure
In [115… arr = [Link]('[Link]')
[Link](arr,bins=[10,20,30,40,50,60,70],log=True)

[Link]('[Link]')

In [116… import numpy as np


import pandas as pd

import [Link] as plt

[Link]('default')

In [117… # code here


df = pd.read_csv('[Link]
[Link]()

[Link] 29/77
2/12/25, 3:38 PM 15-Matplotlib

Out[117…
Unnamed: Temporal Tempora
Position Country City/Town Year PM2.5 PM10
0 coverage coverage.1

0 0 1 India Kanpur 2016 173 >75% 319 NaN

1 1 2 India Faridabad 2016 172 >75% 316 NaN

50% -<
2 2 3 India Gaya 2016 149 275 NaN
75%

3 3 4 India Varanasi 2016 146 >75% 260 NaN

4 4 5 India Patna 2016 144 >75% 266 NaN

In [118… iran_series = [Link]('Country == "Iran"').groupby('Year')['PM2.5'].sum()


china_series = [Link]('Country == "China"').groupby('Year')['PM2.5'].sum()

In [119… [Link](iran_series.index,iran_series.values,label='Iran',linestyle='dashed')
[Link](china_series.index,china_series.values,label='China',
linestyle='dotted',color='red')
[Link]('Year')
[Link]('PM2.5')
[Link]('PM2.5 Over the years')
[Link](df['Year'].value_counts().index)
[Link]()
[Link]()
[Link]()

In [120… # code here


[Link](df['PM10'],density=True,bins=50,facecolor='green',alpha=0.6)

[Link] 30/77
2/12/25, 3:38 PM 15-Matplotlib

[Link]('Bins')
[Link]('Probability')
[Link]('Histogram of PM10')
[Link]()
[Link]()

In [121… # code here


chile_df = [Link]("Country == 'Chile'")
poland_df = [Link]("Country == 'Poland'")

In [122… [Link](chile_df['PM2.5'],chile_df['PM10'],marker="+",color='red',
label='Chile')
[Link](poland_df['PM2.5'],poland_df['PM10'],marker="D",color='black',
label='Poland')
[Link]('PM2.5')
[Link]('PM10')
[Link]('PM2.5 Vs PM10 for Chile and Poland')
[Link]()
[Link]()
[Link]()

[Link] 31/77
2/12/25, 3:38 PM 15-Matplotlib

In [123… # code here


freq_ser = df['Country'].value_counts().head()

In [124… [Link](freq_ser,labels=freq_ser.index,autopct='%0.1f%%')
[Link]()

In [125… # code here


[Link](freq_ser.index,freq_ser)

[Link] 32/77
2/12/25, 3:38 PM 15-Matplotlib

[Link]('Country')
[Link]('Frequency Count')
[Link]()

In [126… # code here


df = pd.read_csv('[Link]
df

Out[126… month_number facecream facewash toothpaste bathingsoap shampoo moisturiz

0 1 2500 1500 5200 9200 1200 15

1 2 2630 1200 5100 6100 2100 12

2 3 2140 1340 4550 9550 3550 13

3 4 3400 1130 5870 8870 1870 11

4 5 3600 1740 4560 7760 1560 17

5 6 2760 1555 4890 7490 1890 15

6 7 2980 1120 4780 8980 1780 11

7 8 3700 1400 5860 9960 2860 14

8 9 3540 1780 6100 8100 2100 17

9 10 1990 1890 8300 10300 2300 18

10 11 2340 2100 7300 13300 2400 21

11 12 2900 1760 7400 14400 1800 17

[Link] 33/77
2/12/25, 3:38 PM 15-Matplotlib

In [127… [Link](df['month_number'],df['total_profit'],label='Month on month Profit',


color='b',marker='o',linestyle='dotted')
[Link]('Month')
[Link]('Total Profit')
[Link]('Company sales profit')
[Link](loc="upper left")
[Link]()

In [128… # code here


labels = df[df['month_number'] == 3].iloc[:,1:7].stack().index.get_level_values(
values = df[df['month_number'] == 3].iloc[:,1:7].stack().values

In [129… [Link](values,labels=labels,autopct='%0.1f%%',explode=[0,0,0.1,0,0,0],
shadow=True)
[Link]("Sales in March")
[Link]()

[Link] 34/77
2/12/25, 3:38 PM 15-Matplotlib

In [130… # code here


monthList = df['month_number'].tolist()

[Link](monthList, df['facecream'], label = 'Face cream', linestyle='dotted',

marker='o', linewidth=3)
[Link](monthList, df['toothpaste'], label = 'Tooth Paste', marker='o',
linewidth=3)
[Link](monthList, df['bathingsoap'], label = 'Bathing Soap', marker='o',
linewidth=3)
[Link](monthList, df['shampoo'], label = 'Shampoo', linestyle='dashdot',
linewidth=3)
[Link](monthList, df['moisturizer'], label = 'Moisturizer', marker='o',
linewidth=3)
[Link](monthList, df['facewash'], label = 'Face Wash', linestyle='dashed',
linewidth=2)

[Link]('Month Number')
[Link]('Sales units in number')
[Link](loc='upper right')
[Link](monthList)
[Link]('Sales data')
[Link]()

[Link] 35/77
2/12/25, 3:38 PM 15-Matplotlib

In [131… # code here


df['date'] = pd.to_datetime(['2020-{}-01'.format(month) for month in df[
'month_number']])

In [132… final_df = [Link](df['date'].[Link]).sum(numeric_only=True)

In [133… i = -1
for col in final_df.columns[1:7]:
[Link](final_df.index + i,final_df[col],width=0.15,label=col)
i = i - 0.15

[Link](final_df.index-1.4,final_df.index)
[Link]('Product')
[Link]('Sales')
[Link]()
[Link]()

[Link] 36/77
2/12/25, 3:38 PM 15-Matplotlib

In [134… all_cols = []

for col in final_df.columns[1:7]:


if len(all_cols) == 0:
[Link](final_df.index,final_df[col],label=col)
else:
[Link](final_df.index,final_df[col],bottom=sum(all_cols),label=col)
all_cols.append(final_df[col])

[Link](final_df.index - 0.02, final_df.index)


[Link]()
[Link]()

[Link] 37/77
2/12/25, 3:38 PM 15-Matplotlib

Advance Matplotlib
In [135… import warnings
[Link]('ignore')

In [136… iris = pd.read_csv("[Link]")


[Link]()

Out[136… Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species

0 1 5.1 3.5 1.4 0.2 Iris-setosa

1 2 4.9 3.0 1.4 0.2 Iris-setosa

2 3 4.7 3.2 1.3 0.2 Iris-setosa

3 4 4.6 3.1 1.5 0.2 Iris-setosa

4 5 5.0 3.6 1.4 0.2 Iris-setosa

In [137… iris['Species'] = iris['Species'].replace({'Iris-setosa':0,'Iris-versicolor':1,'


[Link](5)

[Link] 38/77
2/12/25, 3:38 PM 15-Matplotlib

Out[137… Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species

75 76 6.6 3.0 4.4 1.4 1

35 36 5.0 3.2 1.2 0.2 0

106 107 4.9 2.5 4.5 1.7 2

115 116 6.4 3.2 5.3 2.3 2

138 139 6.0 3.0 4.8 1.8 2

In [138… [Link]('SepalLengthCm','PetalLengthCm',data = iris,c = 'Species',cmap = 'je


[Link]('SepalLengthCm') # matplotlib cmap search on google for variety
[Link]('PetalLengthCm')
[Link]()

Out[138… <[Link] at 0x1a0f6059350>

Plot Size
In [139… [Link](figsize = (5,3))

[Link]('SepalLengthCm','PetalLengthCm',data = iris,c = 'Species',cmap = 'je


[Link]('SepalLengthCm') # matplotlib cmap search on google for variety
[Link]('PetalLengthCm')
[Link]()

Out[139… <[Link] at 0x1a0f5d87b50>

[Link] 39/77
2/12/25, 3:38 PM 15-Matplotlib

Annotation
In [140… batters = pd.read_csv("[Link]")

In [141… sample_df = [Link](100).sample(25)


sample_df

[Link] 40/77
2/12/25, 3:38 PM 15-Matplotlib

Out[141… batter runs avg strike_rate

92 STR Binny 880 19.130435 125.714286

74 IK Pathan 1150 21.698113 116.751269

46 JP Duminy 2029 39.784314 120.773810

95 MS Bisla 798 21.000000 108.276798

22 PA Patel 2848 22.603175 116.625717

30 RA Jadeja 2502 26.617021 122.108346

56 PP Shaw 1588 25.206349 143.580470

35 WP Saha 2427 25.281250 124.397745

66 KH Pandya 1326 22.100000 132.203390

38 SR Tendulkar 2334 33.826087 114.187867

55 KC Sangakkara 1687 25.953846 118.469101

53 MK Tiwary 1695 28.728814 113.834788

37 MA Agarwal 2335 22.669903 129.506378

2 DA Warner 5883 41.429577 136.401577

11 AT Rayudu 4190 28.896552 124.148148

93 Harbhajan Singh 833 15.145455 130.974843

80 SP Narine 1025 14.855072 154.367470

76 ML Hayden 1107 35.709677 131.942789

31 SPD Smith 2495 34.652778 124.812406

94 SO Hetmyer 831 30.777778 144.020797

49 Shubman Gill 1900 32.203390 122.186495

4 SK Raina 5536 32.374269 132.535312

90 MM Ali 910 23.333333 139.570552

14 SR Watson 3880 30.793651 134.163209

86 A Symonds 974 36.074074 124.711908

In [142… [Link](figsize = (18,10))

[Link]('avg','strike_rate', data = sample_df, s = 'runs')

for i in range (sample_df.shape[0]):


[Link](sample_df['avg'].values[i],sample_df['strike_rate'].values[i],sampl

[Link] 41/77
2/12/25, 3:38 PM 15-Matplotlib

In [143… x = [1,2,3,4]
y = [5,6,7,8]

[Link](x,y)
[Link](1,5,'Point 1')
[Link](2,6,'Point 2')
[Link](3,7,'Point 3')
[Link](4,8,'Point 4',fontdict={'size':12,'color':'brown'})

Out[143… Text(4, 8, 'Point 4')

Horizontal and Vertical lines

[Link] 42/77
2/12/25, 3:38 PM 15-Matplotlib

In [144… [Link](figsize = (18,10))

[Link]('avg','strike_rate', data = sample_df, s = 'runs')

[Link](110,color='red')
[Link](130,color='green')
[Link](30,color='red')

for i in range (sample_df.shape[0]):


[Link](sample_df['avg'].values[i],sample_df['strike_rate'].values[i],sampl

Subplots
In [146… fig,ax = [Link]()

[Link]('avg','strike_rate',data = batters)
ax.set_title('something')
ax.set_xlabel('Avg')
ax.set_ylabel('Strike rate')
[Link]()

[Link] 43/77
2/12/25, 3:38 PM 15-Matplotlib

In [147… fig,ax = [Link](nrows = 2, ncols = 1,sharex = True,figsize = (10,6))


ax[0].scatter(batters['avg'],batters['strike_rate'],color = 'cyan')
ax[1].scatter(batters['avg'],batters['runs'],color = 'green')

ax[0].set_title('Avg Vs Strike Rate')


ax[0].set_ylabel('Strike Rate')

ax[1].set_title('Avg Vs Runs')
ax[1].set_ylabel('Runs')
ax[1].set_xlabel('Avg')

Out[147… Text(0.5, 0, 'Avg')

[Link] 44/77
2/12/25, 3:38 PM 15-Matplotlib

In [148… fig,ax = [Link](nrows = 2, ncols = 2) #,sharex = True,figsize = (10,6))

ax[0,0].scatter(batters['avg'],batters['strike_rate'],c= 'red')
ax[0,1].scatter(batters['avg'],batters['runs'],c = 'green')
ax[1,0].hist(batters['avg'])
ax[1,1].hist(batters['runs'])

Out[148… (array([499., 40., 19., 19., 9., 6., 4., 4., 3., 2.]),
array([ 0. , 663.4, 1326.8, 1990.2, 2653.6, 3317. , 3980.4, 4643.8,
5307.2, 5970.6, 6634. ]),
<BarContainer object of 10 artists>)

[Link] 45/77
2/12/25, 3:38 PM 15-Matplotlib

In [149… fig = [Link]()

ax1 = fig.add_subplot(2,2,1)
[Link](batters['avg'],batters['strike_rate'],color='red')

ax2 = fig.add_subplot(2,2,2)
[Link](batters['runs'])

ax3 = fig.add_subplot(2,2,3)
[Link](batters['avg'])

Out[149… (array([102., 125., 103., 82., 78., 43., 22., 14., 2., 1.]),
array([ 0. , 5.56666667, 11.13333333, 16.7 , 22.26666667,
27.83333333, 33.4 , 38.96666667, 44.53333333, 50.1 ,
55.66666667]),
<BarContainer object of 10 artists>)

In [150… fig, ax = [Link](nrows=2,ncols=2,sharex=True,figsize=(6,3))

ax[1,1]

Out[150… <Axes: >

[Link] 46/77
2/12/25, 3:38 PM 15-Matplotlib

3D Scatter Plots
In [151… batters

fig = [Link]()

ax = [Link](projection='3d')

ax.scatter3D(batters['runs'],batters['avg'],batters['strike_rate'],marker='+')
ax.set_title('IPL batsman analysis')

ax.set_xlabel('Runs')
ax.set_ylabel('Avg')
ax.set_zlabel('SR')

Out[151… Text(0.5, 0, 'SR')

[Link] 47/77
2/12/25, 3:38 PM 15-Matplotlib

3D Line Plot
In [152… x = [0,1,5,25]
y = [0,10,13,0]
z = [0,13,20,9]

fig = [Link]()

ax = [Link](projection='3d')

ax.scatter3D(x,y,z,s=[100,100,100,100])
ax.plot3D(x,y,z,color='red')

Out[152… [<mpl_toolkits.mplot3d.art3d.Line3D at 0x1a0f5ab3a10>]

3D Surface Plots
In [5]: x = [Link](-10,10,100)
y = [Link](-10,10,100)

xx, yy = [Link](x,y)

z = xx**2 + yy**2
[Link]

fig = [Link](figsize=(12,8))

ax = [Link](projection='3d')

p = ax.plot_surface(xx,yy,z,cmap='viridis')
[Link](p)

[Link] 48/77
2/12/25, 3:38 PM 15-Matplotlib

Out[5]: <[Link] at 0x2226781f790>

In [6]: z = [Link](xx) + [Link](yy)

fig = [Link](figsize=(12,8))

ax = [Link](projection='3d')

p = ax.plot_surface(xx,yy,z,cmap='viridis')
[Link](p)

Out[6]: <[Link] at 0x222672ee850>

[Link] 49/77
2/12/25, 3:38 PM 15-Matplotlib

In [11]: import numpy as np


import pandas as pd
import seaborn as sns
import [Link] as plt
import warnings
[Link]("ignore")

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[11], line 6
4 import [Link] as plt
5 import warnings
----> 6 [Link]("ignore")

NameError: name 'warnnings' is not defined

In [12]: z = [Link](xx) + [Link](xx)

fig = [Link](figsize=(12,8))

ax = [Link](projection='3d')

p = ax.plot_surface(xx,yy,z,cmap='viridis')
[Link](p)

C:\Users\goura\AppData\Local\Temp\ipykernel_200\[Link]: RuntimeWarning: i
nvalid value encountered in log
z = [Link](xx) + [Link](xx)
Out[12]: <[Link] at 0x22267c08b50>

[Link] 50/77
2/12/25, 3:38 PM 15-Matplotlib

In [13]: fig = [Link](figsize=(12,8))

ax = [Link](projection='3d')

p = ax.plot_surface(xx,yy,z,cmap='viridis')
[Link](p)

Out[13]: <[Link] at 0x22269f58b50>

[Link] 51/77
2/12/25, 3:38 PM 15-Matplotlib

Contour Plots
In [17]: # 3D Surface Plot
fig = [Link](figsize=(12, 8))
ax = fig.add_subplot(projection='3d') # Corrected way to add 3D subplot
p = ax.plot_surface(xx, yy, z, cmap='viridis')
[Link](p)

Out[17]: <[Link] at 0x2226b6d0850>

[Link] 52/77
2/12/25, 3:38 PM 15-Matplotlib

In [19]: # Contour Plot


fig, ax = [Link](figsize=(12, 8)) # Corrected subplot creation
p = [Link](xx, yy, z, cmap='viridis')
[Link](p)

[Link]()

[Link] 53/77
2/12/25, 3:38 PM 15-Matplotlib

In [20]: z = [Link](xx) + [Link](yy)

fig = [Link](figsize=(12,8))

ax = [Link]()

p = [Link](xx,yy,z,cmap='viridis')
[Link](p)

Out[20]: <[Link] at 0x2226bc37310>

[Link] 54/77
2/12/25, 3:38 PM 15-Matplotlib

Heatmap
In [23]: delivery = pd.read_csv("ball_deliveries.csv")
[Link]()

Out[23]: match_id inning batting_team bowling_team over ball batsman non_striker bo

Royal
Sunrisers DA
0 1 1 Challengers 1 1 S Dhawan
Hyderabad Warner
Bangalore

Royal
Sunrisers DA
1 1 1 Challengers 1 2 S Dhawan
Hyderabad Warner
Bangalore

Royal
Sunrisers DA
2 1 1 Challengers 1 3 S Dhawan
Hyderabad Warner
Bangalore

Royal
Sunrisers DA
3 1 1 Challengers 1 4 S Dhawan
Hyderabad Warner
Bangalore

Royal
Sunrisers DA
4 1 1 Challengers 1 5 S Dhawan
Hyderabad Warner
Bangalore

5 rows × 21 columns

In [24]: temp_df = delivery[(delivery['ball'].isin([1,2,3,4,5,6])) & (delivery['batsman_r

[Link] 55/77
2/12/25, 3:38 PM 15-Matplotlib

In [25]: grid = temp_df.pivot_table(index='over',columns='ball',values='batsman_runs',agg

In [26]: [Link](figsize=(10,5))
[Link](grid)
[Link](delivery['over'].unique(), list(range(1,21)))
[Link]([Link](0,6), list(range(1,7)))
[Link]()

Out[26]: <[Link] at 0x2226ff80810>

Pandas Plot()
In [27]: # on a series

s = [Link]([1,2,3,4,5,6,7])
[Link](kind='pie')

Out[27]: <Axes: >

[Link] 56/77
2/12/25, 3:38 PM 15-Matplotlib

In [28]: # can be used on a dataframe as well

import seaborn as sns


tips = sns.load_dataset('tips')

tips['size'] = tips['size'] * 100

[Link]()

Out[28]: total_bill tip sex smoker day time size

0 16.99 1.01 Female No Sun Dinner 200

1 10.34 1.66 Male No Sun Dinner 300

2 21.01 3.50 Male No Sun Dinner 300

3 23.68 3.31 Male No Sun Dinner 200

4 24.59 3.61 Female No Sun Dinner 400

In [29]: # Scatter plot -> labels -> markers -> figsize -> color -> cmap
[Link](kind='scatter',x='total_bill',y='tip',title='Cost Analysis',marker='+'
figsize=(10,6),s='size',c='sex',cmap='viridis')

Out[29]: <Axes: title={'center': 'Cost Analysis'}, xlabel='total_bill', ylabel='tip'>

[Link] 57/77
2/12/25, 3:38 PM 15-Matplotlib

In [30]: stocks = pd.read_csv(


'[Link]
[Link]()

Out[30]: Date MSFT FB AAPL

0 2021-05-24 249.679993 328.730011 124.610001

1 2021-05-31 250.789993 330.350006 125.889999

2 2021-06-07 257.890015 331.260010 127.349998

3 2021-06-14 259.429993 329.660004 130.460007

4 2021-06-21 265.019989 341.369995 133.110001

In [31]: # line plot


stocks['MSFT'].plot(kind='line')

Out[31]: <Axes: >

[Link] 58/77
2/12/25, 3:38 PM 15-Matplotlib

In [32]: [Link](kind='line',x='Date')

Out[32]: <Axes: xlabel='Date'>

In [33]: stocks[['Date','AAPL','FB']].plot(kind='line',x='Date')

Out[33]: <Axes: xlabel='Date'>

[Link] 59/77
2/12/25, 3:38 PM 15-Matplotlib

In [34]: # bar chart -> single -> horizontal -> multiple


# using tips
temp = pd.read_csv("batsman_season_record.csv")
[Link]()

Out[34]: batsman 2015 2016 2017

0 AB de Villiers 513 687 216

1 DA Warner 562 848 641

2 MS Dhoni 372 284 290

3 RG Sharma 482 489 333

4 V Kohli 505 973 308

In [35]: [Link]('sex')['total_bill'].mean().plot(kind='bar')

C:\Users\goura\AppData\Local\Temp\ipykernel_200\[Link]: FutureWarning: Th
e default of observed=False is deprecated and will be changed to True in a future
version of pandas. Pass observed=False to retain current behavior or observed=Tru
e to adopt the future default and silence this warning.
[Link]('sex')['total_bill'].mean().plot(kind='bar')
Out[35]: <Axes: xlabel='sex'>

[Link] 60/77
2/12/25, 3:38 PM 15-Matplotlib

In [36]: temp['2015'].plot(kind='bar')

Out[36]: <Axes: >

In [37]: [Link](kind='bar')

[Link] 61/77
2/12/25, 3:38 PM 15-Matplotlib

Out[37]: <Axes: >

In [38]: # stacked bar chart


[Link](kind='bar',stacked=True)

Out[38]: <Axes: >

In [39]: # histogram
# using stocks

[Link] 62/77
2/12/25, 3:38 PM 15-Matplotlib

stocks[['MSFT','FB']].plot(kind='hist',bins=40)

Out[39]: <Axes: ylabel='Frequency'>

In [40]: # pie -> single and multiple


df = [Link](
{
'batsman':['Dhawan','Rohit','Kohli','SKY','Pandya','Pant'],
'match1':[120,90,35,45,12,10],
'match2':[0,1,123,130,34,45],
'match3':[50,24,145,45,10,90]
}
)

[Link]()

Out[40]: batsman match1 match2 match3

0 Dhawan 120 0 50

1 Rohit 90 1 24

2 Kohli 35 123 145

3 SKY 45 130 45

4 Pandya 12 34 10

In [41]: df['match1'].plot(kind='pie',labels=df['batsman'].values,autopct='%0.1f%%')

Out[41]: <Axes: ylabel='match1'>

[Link] 63/77
2/12/25, 3:38 PM 15-Matplotlib

In [42]: # multiple pie charts

df[['match1','match2','match3']].plot(kind='pie',subplots=True,figsize=(15,8))

Out[42]: array([<Axes: ylabel='match1'>, <Axes: ylabel='match2'>,


<Axes: ylabel='match3'>], dtype=object)

In [43]: # multiple separate graphs together


# using stocks

[Link](kind='line',subplots=True)

Out[43]: array([<Axes: >, <Axes: >, <Axes: >], dtype=object)

[Link] 64/77
2/12/25, 3:38 PM 15-Matplotlib

In [44]: # on multiindex dataframes


# using tips

tips.pivot_table(index=['day','time'],columns=['sex','smoker'],values='total_bil
).plot(kind='pie',subplots=True,figsize=(20,10))

C:\Users\goura\AppData\Local\Temp\ipykernel_200\[Link]: FutureWarning: Th
e default value of observed=False is deprecated and will change to observed=True
in a future version of pandas. Specify observed=False to silence this warning and
retain the current behavior
tips.pivot_table(index=['day','time'],columns=['sex','smoker'],values='total_bi
ll',aggfunc='mean'
Out[44]: array([<Axes: ylabel='(Male, Yes)'>, <Axes: ylabel='(Male, No)'>,
<Axes: ylabel='(Female, Yes)'>, <Axes: ylabel='(Female, No)'>],
dtype=object)

In [45]: import numpy as np


import pandas as pd
import [Link] as plt

from [Link] import LabelEncoder

[Link]('default')

In [46]: df = pd.read_csv('[Link]
[Link]()

[Link] 65/77
2/12/25, 3:38 PM 15-Matplotlib

Out[46]: Total Cap.


Planned Other
Power Monitored Under Forced
Dates Maintanence Reasons
Station Cap.(MW) Maintenace Maintanence(MW)
(MW) (MW)
(MW)

2017-
0 Delhi 2235.4 135.00 0.00 135.0 0
09-01

2017-
1 Haryana 2720.0 2470.00 0.00 2470.0 0
09-01

2017- Himachal
2 3378.0 379.00 0.00 231.0 0
09-01 Pradesh

Jammu
2017-
3 and 1285.0 150.00 0.00 0.0 0
09-01
Kashmir

2017-
4 Punjab 3826.3 2697.65 77.65 2620.0 0
09-01

In [47]: most_freq = df['Power Station'].value_counts().head().[Link]()

In [48]: temp_df = df[df['Power Station'].isin(most_freq)]

In [49]: encoder = LabelEncoder()


temp_df['Power Station'] = encoder.fit_transform(temp_df['Power Station'])

C:\Users\goura\AppData\Local\Temp\ipykernel_200\[Link]: SettingWithCopyW
arning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: [Link]


e/user_guide/[Link]#returning-a-view-versus-a-copy
temp_df['Power Station'] = encoder.fit_transform(temp_df['Power Station'])

In [50]: fig, ax = [Link](1,2, figsize=(12,5))

ax[0].scatter(temp_df['Monitored Cap.(MW)'],temp_df[
'Total Cap. Under Maintenace (MW)'],c=temp_df['Power Station'])
ax[0].axvline(temp_df['Monitored Cap.(MW)'].mean(),c='red')
ax[0].axhline(temp_df['Total Cap. Under Maintenace (MW)'].mean(),c='black')
ax[0].set_xlabel('Monitored Cap')
ax[0].set_ylabel('Total Cap under Maintaince')
ax[0].set_title('Monitored Vs Under Maintainence Cap')

ax[1].scatter(temp_df['Monitored Cap.(MW)'],temp_df['Actual(MU)'],
c=temp_df['Power Station'])
ax[1].axvline(temp_df['Monitored Cap.(MW)'].mean(),c='red')
ax[1].axhline(temp_df['Actual(MU)'].mean(),c='black')
ax[1].set_xlabel('Monitored Cap')
ax[1].set_ylabel('Actual(MU)')
ax[1].set_title('Monitored Vs Actual(MU)')

Out[50]: Text(0.5, 1.0, 'Monitored Vs Actual(MU)')

[Link] 66/77
2/12/25, 3:38 PM 15-Matplotlib

In [51]: fig = [Link]()

ax = [Link](projection='3d')

ax.scatter3D(temp_df['Monitored Cap.(MW)'],
temp_df['Total Cap. Under Maintenace (MW)'],
temp_df['Forced Maintanence(MW)'],c=temp_df['Power Station'])
ax.set_xlabel('Monitored Cap.(MW)')
ax.set_ylabel('Total Cap. Under Maintenace (MW)')
ax.set_zlabel('Forced Maintanence(MW)')
ax.set_title('3D plot of various metrics')

[Link]()

In [52]: x = [Link](-10,10,100)
y = [Link](-10,10,100)

xx, yy = [Link](x,y)

[Link] 67/77
2/12/25, 3:38 PM 15-Matplotlib

z = [Link](xx) - [Link](yy)

In [53]: fig = [Link](figsize=(10,10))

ax = [Link](projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.plot_surface(xx,yy,z, cmap='viridis')
[Link]()

In [54]: # code here


fig = [Link](figsize=(10,10))

ax = [Link]()
[Link](xx,yy,z, cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')
[Link]()

[Link] 68/77
2/12/25, 3:38 PM 15-Matplotlib

In [55]: # code here


fig = [Link]()

ax = [Link]()
[Link](xx,yy,z, cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')
[Link]()

[Link] 69/77
2/12/25, 3:38 PM 15-Matplotlib

In [56]: nifty = pd.read_csv('[Link]


[Link]()

Out[56]: Prev
Date Symbol Series Open High Low Last Close VWAP Vol
Close

2000-
0 HDFCBANK EQ 157.40 166.00 170.00 166.00 170.00 170.00 169.52 3
01-03

2000-
1 HDFCBANK EQ 170.00 182.00 183.45 171.00 174.00 173.80 174.99 16
01-04

2000-
2 HDFCBANK EQ 173.80 170.00 173.90 165.00 168.00 166.95 169.20 15
01-05

2000-
3 HDFCBANK EQ 166.95 168.00 170.00 165.30 168.95 168.30 168.44 8
01-06

2000-
4 HDFCBANK EQ 168.30 162.15 171.00 162.15 170.75 168.35 166.79 8
01-07

In [57]: # code here


nifty['Date'] = pd.to_datetime(nifty['Date'])

In [58]: nifty.set_index('Date',inplace=True)

In [59]: temp_df = nifty[[Link] == 2020]

In [61]: top_5 = temp_df.groupby('Symbol')['Turnover'].sum().sort_values(


ascending=False).head().index

[Link] 70/77
2/12/25, 3:38 PM 15-Matplotlib

In [62]: tempm_df = temp_df[temp_df['Symbol'].isin(top_5)]

In [63]: ax = temp_df[temp_df.Symbol=='RELIANCE'].plot(y='Close', use_index=True)

for company in top_5[1:]:


temp_df[temp_df.Symbol==company].plot(y='Close', label=company,
use_index=True, ax=ax)

In [64]: # code here


temp_df = nifty[[Link] == 2021]
top_5 = temp_df.groupby('Symbol')['Turnover'].sum().sort_values(ascending=False
).head().index
temp_df = temp_df[temp_df['Symbol'].isin(top_5)]

temp_df['Symbol'] = temp_df['Symbol'].astype('category')
temp_df.plot(kind='scatter', x='Close', y='Volume', c='Symbol',
colormap='viridis')

Out[64]: <Axes: xlabel='Close', ylabel='Volume'>

[Link] 71/77
2/12/25, 3:38 PM 15-Matplotlib

In [65]: time = [Link](0, 10, 100)


x = [Link](time)
y = [Link](time)
z = time

# Create a DataFrame from the dataset


data = [Link]({'time': time, 'x': x, 'y': y, 'z': z})

data

Out[65]: time x y z

0 0.00000 0.000000 1.000000 0.00000

1 0.10101 0.100838 0.994903 0.10101

2 0.20202 0.200649 0.979663 0.20202

3 0.30303 0.298414 0.954437 0.30303

4 0.40404 0.393137 0.919480 0.40404

... ... ... ... ...

95 9.59596 -0.170347 -0.985384 9.59596

96 9.69697 -0.268843 -0.963184 9.69697

97 9.79798 -0.364599 -0.931165 9.79798

98 9.89899 -0.456637 -0.889653 9.89899

99 10.00000 -0.544021 -0.839072 10.00000

100 rows × 4 columns

[Link] 72/77
2/12/25, 3:38 PM 15-Matplotlib

In [66]: fig = [Link]()

ax = [Link](projection='3d')

[Link](data['time'],data['x'],data['y'], c=data['z'])

ax.set_xlabel('time')
ax.set_ylabel('X - Axis')
ax.set_zlabel('Y - Axis')

[Link]('Vibration Characterstics of a car body')


[Link]()

In [67]: # code here


x = [Link](-10,10,100)
y = [Link](-10,10,100)

xx,yy = [Link](x,y)

z = [Link]([Link](xx**2 + yy**2))

In [68]: fig = [Link]()


ax = [Link](projection='3d')

ax.plot_surface(xx,yy,z,cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

[Link]()

[Link] 73/77
2/12/25, 3:38 PM 15-Matplotlib

In [69]: fig = [Link]()


ax = [Link]()

[Link](xx,yy,z,cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')

[Link]()

[Link] 74/77
2/12/25, 3:38 PM 15-Matplotlib

In [70]: fig = [Link]()


ax = [Link]()

[Link](xx,yy,z,cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')

[Link]()

In [71]: # code here


# code here
x = [Link](-10,10,100)
y = [Link](-10,10,100)

xx,yy = [Link](x,y)

z = [Link](np.log2(xx**2 + yy**2))

In [72]: fig = [Link]()


ax = [Link](projection='3d')

ax.plot_surface(xx,yy,z,cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

[Link]()

[Link] 75/77
2/12/25, 3:38 PM 15-Matplotlib

In [73]: fig = [Link]()


ax = [Link]()

[Link](xx,yy,z,cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')

[Link]()

[Link] 76/77
2/12/25, 3:38 PM 15-Matplotlib

In [74]: fig = [Link]()


ax = [Link]()

[Link](xx,yy,z,cmap='viridis')
ax.set_xlabel('X')
ax.set_ylabel('Y')

[Link]()

In [ ]:

[Link] 77/77

You might also like