0 ratings0% found this document useful (0 votes) 35 views8 pagesMatplotlib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
Data Visualization with Matplotlib
1 Line Plot - Bar Chart - Scatter Diagram - Histogram
1.1 Create the x variable with 200 elements from -10 to 10. Create the y
variable which has the sine (np.sin()) of x.
Requirements:
* Plot the curve
[16]: from matplotlib import pyplot as plt
import numpy as np
x = mp.linspace(~10
y > mp.sin(x)
plt.plot(x.y)
plt.show()
0,200)
100
075
050
0.25
0.00
-0.25
0.50
-0.75
-1.00
-100 -75 -50 -25 00 25 50 75 100
« plot the elements of x (above exercise):
ith an x
ith a green 0ra
(2a):
75 -50 -25 00 25 50 75 100
10.0
100
075
050
025
0.00
0.25
0.50
075
-1.00
100
075
75 50 -25 00 25 50 75 100
-10.0
'* Plot only the elements:
= from the index 50 to 80
— from the index 51 to 56
(22):1.00
075
050
025
0.00
0.25
0.50
075
1.000
0.995
0990
0.985
0.980
0975
0970
485 -480 475 -470 465 4.60 -455 -4.50
1.2 Given the dataset weight-height.csv. Generate plots described as follows:
© use dil].values to get a numpy array out of the data-frame columns
* plot the height vs weight
(23):250
200
150
100
55. oO 6 70 B 0
© plot the male with blue and female with red in the same plot
(2a): [27
250
200
180
100
1.3. Given a esv file ‘company-sales.csv’. Generate line plots describe as follows:
© Read the Total profit of all months and show it using a line plot
© The Total profit data is provided for each month. Generated line plot must incnde the
following properties:— X label name = Month Number
— ¥ label name = Total profit,
(37): [27
Cc fit per ith
sooo00 ‘ompany profit per mont
400000
300000
200000
100000
12 3 4 5 6 7 8 9 DU DB
Month number
'* Get Total profit of all months and show line plot with the following Style properties:
— Line Style dotted and Line-color should be red
Show legend at the lower right location.
~ X label name — Month Number
~ ¥ label name = Sold units number
— Add a circle marker. ¢ Line marker color as read # Line width should be 3
(29): (77(at):
500000
400000
300000
Profit in dollar
200000
100000
Company Sales data of last year
“®- Profit data of last year
12 3 4 5 6 7 8 3 DU DB
Month Number
‘* Read all product sales data and show it using a multiline plot
18000
15000
12000
10000
8000
6000
Sales units in number
4000
2000
1000
Sales data
“—® Face cream Sales Data
“-® Face Wash Sales Data
—® bothPaste Sales Data
—@ ‘bothPaste Sales Data
© bothPaste Sales Data
—® ‘othPaste Sales Data
BOSSE ees
12 3 4 5 6 7 8 3 DU DR
Month Number
‘© Read face cream and facewash product sales data and show it using the bar chart
6(33):
(38):
import pandas as pd
import matplotlib.pyplot as plt
af = pd.read_csv("conpany-sales.csv")
nonthList = df [‘month_nunber'] values
faceCrenSalesData ~ df ['facecrean'] values
facelWashSalesData = df ['facewash'].values
pit.bar([a-0.25 for a in monthList], faceCrenSalesData, width~ 0.25, label =,
»'Face Cream sales data’, align-'edge')
plt.bar({a+0.25 for a in monthList], faceWashSalesData, widt!
'Face Wash sales data’, align-'edge')
plt.xlabel('Month Number")
pit ylabel('Sales units in number')
plt.legend(loc-' upper left")
plt.title(" Sales data’)
pit.xticks(monthList)
plt.grid(True, linewidth- 1, linestyle-"--")
plt.title('Facewash and facecream sales data')
pltshow()
0.25, label
Facewash and facecream sales data
lm Face Cream sales data |
3500 J gum Face Wash sales data |
3000
2500
2000
1500
Sales units in number
1000
500
123 4 5 6 7 8 3 DU DR
Month Number
‘* Read the total profit of each month and show it using the histogram to see most: common
profit ranges
7Actual Profit in dollar
Profit data
rs
w
N
lm Profit data
ol
150000 175000 200000 225000250000 300000 350000
profit range in dollar
‘* Read Bathing soap facewash of all months and display it using the Subplot
(36): | 77
Sales units in number
12500
10000
7500
2000
1500
Sales data of a Bathingsoap
Sales data of a facewash
w
4 5 6 7 8 3 DU DB