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

Matplotlib Data Visualization Examples

The document provides examples of using Matplotlib for plotting various types of data visualizations, including temperature against date, average weight with respect to average height, carnival sales reports, and tickets sold throughout the week. Each example includes code snippets demonstrating how to create line graphs and bar charts with appropriate labels and titles. The document emphasizes the use of pandas for handling data frames and saving/loading CSV files.

Uploaded by

gamerred959
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)
5 views5 pages

Matplotlib Data Visualization Examples

The document provides examples of using Matplotlib for plotting various types of data visualizations, including temperature against date, average weight with respect to average height, carnival sales reports, and tickets sold throughout the week. Each example includes code snippets demonstrating how to create line graphs and bar charts with appropriate labels and titles. The document emphasizes the use of pandas for handling data frames and saving/loading CSV files.

Uploaded by

gamerred959
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

Matplotlib

(Plotting data)
Matplotlib
Plotting Temperature against Height
INPUTS

import [Link] as plt

# list storing date in string format


date = ["25/12", "26/12", "27/12"]

# list storing temperature values


temp = [8.5, 10.5, 6.8]

# create a figure plotting temp versus date


[Link](date, temp, marker='o')

# add labels and title


[Link]("Date")
[Link]("Temperature (°C)")
[Link]("Temperature Variation")

# show the figure


[Link]()

LINE GRAPH
Plotting Avg. Weight with respect to avg. Height
INPUTS

import [Link] as plt


import pandas as pd

# data
height = [119.9, 124.5, 129.5, 134.6, 130.7, 147.3, 152.4, 157.0, 162.0]
weight = [19.7, 21.3, 23.5, 25.9, 28.5, 32.1, 35.7, 39.6, 43.2]

# create dataframe
df = [Link]({"height": height, "weight": weight})

# set labels
[Link]("Weight in kg")
[Link]("Height in cm")
[Link]("Average weight with respect to average height")

# plot with marker and green dash-dot line


[Link](df["weight"], df["height"],
marker='*', markersize=10,
color='green', linewidth=2, linestyle='dashdot')
[Link]()
Plotting Carnival Sales Report
INPUTS

# Create a DataFrame
df = [Link](data)

# Save the DataFrame to a CSV file


df.to_csv("Daywise_Sales.csv", index=False)

# Read CSV file (use your actual file '[Link]' if provided)


df = pd.read_csv("Daywise_Sales.csv")

# Plot a bar chart


[Link](kind="bar",
x="Day",
y="Sales",
title="Carnival Sales Report",
color=["red", "yellow", "purple", "orange", "blue", "green", "pink"],
edgecolor="green",
linewidth=2)

# Set Y-axis label


[Link]("Sales in Rs")
[Link]()
Tickets Sold Throughout the Week
INPUTS

import [Link] as plt

# Data
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
tickets_sold = [2000, 2800, 3000, 2500, 2300, 2500, 1000]

# Plotting the line plot with magenta color


[Link](days, tickets_sold, color='magenta', marker='o', linestyle='*', linewidth=2)

# Title and labels


[Link]("Tickets Sold Throughout the Week")
[Link]("Day")
[Link]("Tickets Sold")
[Link]()

You might also like