0% found this document useful (0 votes)
7 views7 pages

Graphical Represantation of Data

Matplotlib data representation

Uploaded by

sriwastavsidd
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)
7 views7 pages

Graphical Represantation of Data

Matplotlib data representation

Uploaded by

sriwastavsidd
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/ 7

Disclaimer : Do not Claim ownership

of this document without proof,


doing so will 100% result in harmful
side effect including but not limited
to an untimely departure from planet
Earth .This warning is especially
made for a very specific creature
(Agniva). If you are not this specific
creature you can ignore this warning.
QUESTION 1
Ans –

import matplotlib.pyplot as plt

languages = ['Python', 'Java', 'C++', 'JavaScript', 'Ruby']

votes = [40, 30, 20, 15, 10]

colors = ['blue', 'green', 'red', 'purple', 'orange']

plt.barh(languages, votes, color=colors)

plt.title('Favourite Programming Languages')

plt.xlabel('Number of Votes')

plt.ylabel('Programming Language')

for index, value in enumerate(votes):

plt.text(value, index, str(value))

plt.savefig('favorite_languages_horizontal_bar.png')

plt.show()
QUESTION 2
ANS –

import matplotlib.pyplot as plt

quarters = ['Q1', 'Q2', 'Q3', 'Q4']

hr_expenses = [30, 25, 28, 35]

it_expenses = [40, 38, 42, 45]

marketing_expenses = [25, 28, 30, 32]

plt.bar(quarters, hr_expenses, label='HR', color='blue')

plt.bar(quarters, it_expenses, bottom=hr_expenses, label='IT', color='green')

bottom_expenses = [hr + it for hr, it in zip(hr_expenses, it_expenses)]

plt.bar(quarters, marketing_expenses, bottom=bottom_expenses,


label='Marketing', color='orange')

plt.title('Quarterly Departmental Expenses')

plt.xlabel('Quarter')

plt.ylabel('Expenses (in thousands of dollars)')

plt.legend()

plt.savefig('departmental_expenses_stacked_bar.png')

plt.show()
QUESTION 3
ANS –

import matplotlib.pyplot as plt

days = list(range(1, 11))

city_a = [22, 23, 24, 21, 20, 25, 24, 23, 22, 21]

city_b = [18, 19, 20, 21, 22, 23, 24, 23, 22, 21]

city_c = [28, 27, 26, 25, 24, 23, 22, 21, 20, 19]

plt.figure(figsize=(10, 6))

plt.plot(days, city_a, 'r--', label='City A') # Red dashed line

plt.plot(days, city_b, 'g-.', label='City B') # Green dash-dot line

plt.plot(days, city_c, 'b-', label='City C') # Blue solid line

plt.title('10-Day Temperature Trends')

plt.xlabel('Day')

plt.ylabel('Temperature (°C)')

plt.legend()

plt.savefig('temperature_trends_multi_line.png')

plt.show()
QUESTION 4
ANS –

import matplotlib.pyplot as plt

expenses = [1200, 1500, 1100, 1300, 1600, 1400, 1700, 1800, 1600, 1500,
1700, 1900]

plt.figure(figsize=(10, 6))

plt.hist(expenses, bins=6, edgecolor='black', alpha=0.7)

plt.title('Distribution of Monthly Expenses')

plt.xlabel('Expenses (in dollars)')

plt.ylabel('Frequency')

plt.savefig('monthly_expenses_histogram.png')

plt.show()
OUTPUT –
1. output –

2. output –
3. output –

4. output-

You might also like