0% found this document useful (0 votes)
5 views6 pages

Matplotlib Data Visualization Examples

The document provides various examples of data visualization using Matplotlib in Python, including line plots, scatter plots, box plots, and histograms. Each section contains code snippets demonstrating how to create these plots with sample data. The visualizations illustrate step counts, sales versus price for drinks, and distributions of random data.

Uploaded by

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

Matplotlib Data Visualization Examples

The document provides various examples of data visualization using Matplotlib in Python, including line plots, scatter plots, box plots, and histograms. Each section contains code snippets demonstrating how to create these plots with sample data. The visualizations illustrate step counts, sales versus price for drinks, and distributions of random data.

Uploaded by

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

9.

Matplotlib
#Line plot
Code:
import [Link] as plt

days=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]

steps_walked=[8934,14902,3409,25672,12300,2023,6890]
steps_last_week=[9788,8710,5308,17630,21309,4002,5223]
fig,axs=[Link](1,2,figsize=(12,5))
axs[0].plot(days,steps_walked,"o:r")
axs[1].plot(days,steps_last_week,"v-g")
axs[0].set_title("Step count for this week")
axs[1].set_title("Step count for last week")
axs[0].set_ylabel("steps walked")
axs[0].grid(True)
axs[1].set_ylabel("steps walked")
axs[1].grid(True)
[Link]("Days of the week")
[Link]([2000,30000])
[Link]("step count| This week and last week")
[Link]()

Output:
#Scatterplot
Code:
import [Link] as plt
import numpy as np

low="g"
medium="y"
high="r"
price_orange=[Link]([2.50,1.23,4.02,3.25,5.00,4.40])
sales_per_day_orange=[Link]([34,62,49,22,13,19])
profit_margin_orange=[Link]([20,35,40,20,27.5,15])
sugar_content_orange=[low,high,medium,medium,high,low]
price_apple=[Link]([1.50,2.50,1.15,1.95])
sales_per_day_apple=[Link]([67,34,36,12])
profit_margin_apple=[Link]([20,42.5,33.3,18])
sugar_content_apple=[low,high,medium,low]
[Link](x=price_orange,y=sales_per_day_orange,s=profit_margin_orange*10,c=sugar_co
ntent_orange,alpha=0.5)
[Link](x=price_apple,y=sales_per_day_apple,s=profit_margin_apple*10,c=sugar_conte
nt_apple,marker="v",alpha=0.5)
[Link]("sales vs price for Orange Drinks and Apple Drinks")
[Link](["Orange Drinks","Apple Drinks"])
[Link]("price(Currency Unit)")
[Link]("average weekly sales")
[Link](1.8,60,"colour of marker= sugar content")
[Link]()
Output:

#MATPLOTLIB
Code:
import [Link] as plt
import random
x=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
y=[[Link](1,10) for i in range (15)]
z=[23,45,43,12,17,98,90,78,67,54,19,78,64,33,65]
[Link](x,y)
[Link](x,z)
[Link]('x-aixs')
[Link]('y-axis')
[Link](['input1','input2'],loc='upper left',title='description',fontsize=5)
[Link](fontsize=10,rotation=15,fontweight="bold")
[Link]()
Output:

#BOXPLOT
Code:
y=[[Link](1,10) for i in range(20)]

print(y)
[Link](y,vert=False)

Output:
[4, 3, 1, 3, 4, 6, 8, 4, 6, 7, 9, 9, 6, 9, 1, 3, 5, 2, 10, 5]
{'whiskers': [<[Link].Line2D at 0x1e3f72ffe50>,
<[Link].Line2D at 0x1e3f730cb10>],
'caps': [<[Link].Line2D at 0x1e3f72c7690>,
<[Link].Line2D at 0x1e3f730e1d0>],
'boxes': [<[Link].Line2D at 0x1e3f72ff290>],
'medians': [<[Link].Line2D at 0x1e3f730ec90>],
'fliers': [<[Link].Line2D at 0x1e3f730f790>],
'means': []}
#HISTOGRAM

Code:
from matplotlib import pyplot as plt
import numpy as np
a=[Link]([22,87,5,43,56,73,55,54,11,20,51,5,79,32,27])
fig, ax=[Link](figsize=(10,7))
[Link](a, bins=[0,25,50,75,100],edgecolor="black",rwidth=0.2,color='white')
[Link]()
Output:

You might also like