0% found this document useful (0 votes)
14 views

matplotlib_2D Line Plot

Example of Matplotlib 2d Line

Uploaded by

Amol
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)
14 views

matplotlib_2D Line Plot

Example of Matplotlib 2d Line

Uploaded by

Amol
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
You are on page 1/ 12

Types of Data

• Numerical Data
• Categorical Data
# import the library
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

plt.style.use('default')

2D Line plot

• Bivariate Analysis
• categorical -> numerical and numerical -> numerical
• Use case - Time series data
# plotting a simple function
price = [48000,54000,57000,49000,47000,45000]
year = [2015,2016,2017,2018,2019,2020]

plt.plot(year,price)

[<matplotlib.lines.Line2D at 0x7861f4215cf0>]
# from a pandas dataframe
batsman = pd.read_csv('/content/sample_data/sharma-kohli.csv')
batsman

plt.plot(batsman['index'],batsman['V Kohli'])

[<matplotlib.lines.Line2D at 0x7861f4f78bb0>]
# plotting multiple plots
plt.plot(batsman['index'],batsman['V Kohli'])
plt.plot(batsman['index'],batsman['RG Sharma'])

[<matplotlib.lines.Line2D at 0x7861f553d720>]
# labels title
plt.plot(batsman['index'],batsman['V Kohli'])
plt.plot(batsman['index'],batsman['RG Sharma'])

plt.title('Rohit Sharma Vs Virat Kohli Career Comparison')


plt.xlabel('Season')
plt.ylabel('Runs Scored')

Text(0, 0.5, 'Runs Scored')


# colors(hex) and line(width and style) and marker(size)
plt.plot(batsman['index'],batsman['V Kohli'],color='red')
plt.plot(batsman['index'],batsman['RG Sharma'],color='blue')

plt.title('Rohit Sharma Vs Virat Kohli Career Comparison')


plt.xlabel('Season')
plt.ylabel('Runs Scored')

Text(0, 0.5, 'Runs Scored')


plt.plot(batsman['index'],batsman['V
Kohli'],color='#D9F10F',linestyle='solid',linewidth=3)
plt.plot(batsman['index'],batsman['RG
Sharma'],color='#FC00D6',linestyle='dashdot',linewidth=2)

plt.title('Rohit Sharma Vs Virat Kohli Career Comparison')


plt.xlabel('Season')
plt.ylabel('Runs Scored')

Text(0, 0.5, 'Runs Scored')


plt.plot(batsman['index'],batsman['V
Kohli'],color='#D9F10F',linestyle='solid',linewidth=3,marker='D',marke
rsize=10)
plt.plot(batsman['index'],batsman['RG
Sharma'],color='#FC00D6',linestyle='dashdot',linewidth=2,marker='o')

plt.title('Rohit Sharma Vs Virat Kohli Career Comparison')


plt.xlabel('Season')
plt.ylabel('Runs Scored')

Text(0, 0.5, 'Runs Scored')


# legend -> location
plt.plot(batsman['index'],batsman['V
Kohli'],color='#5f332a',linestyle='solid',linewidth=3,marker='D',marke
rsize=10,label='Virat')
plt.plot(batsman['index'],batsman['RG
Sharma'],color='#FC00D6',linestyle='dashdot',linewidth=2,marker='o',la
bel='Rohit')

plt.title('Rohit Sharma Vs Virat Kohli Career Comparison')


plt.xlabel('Season')
plt.ylabel('Runs Scored')

plt.legend()

<matplotlib.legend.Legend at 0x7861f0739630>
# limiting axes
price = [48000,54000,57000,49000,47000,45000,4500000]
year = [2015,2016,2017,2018,2019,2020,2021]

plt.plot(year,price)
plt.ylim(10000,15000)
plt.xlim(2010,2019)

(2010.0, 2019.0)
# grid
plt.plot(batsman['index'],batsman['V
Kohli'],color='#D9F10F',linestyle='solid',linewidth=3,marker='D',marke
rsize=10)
plt.plot(batsman['index'],batsman['RG
Sharma'],color='#FC00D6',linestyle='dashdot',linewidth=2,marker='o')

plt.title('Rohit Sharma Vs Virat Kohli Career Comparison')


plt.xlabel('Season')
plt.ylabel('Runs Scored')

plt.grid()
# show
plt.plot(batsman['index'],batsman['V
Kohli'],color='#D9F10F',linestyle='solid',linewidth=3,marker='D',marke
rsize=10)
plt.plot(batsman['index'],batsman['RG
Sharma'],color='#FC00D6',linestyle='dashdot',linewidth=2,marker='o')

plt.title('Rohit Sharma Vs Virat Kohli Career Comparison')


plt.xlabel('Season')
plt.ylabel('Runs Scored')

plt.grid()

plt.show()

You might also like