2/22/2023

Histogram drawing using matplotlib by python code.

 Refer to code:

first one is draw histogram

second one is for drawing simple graph


drawing histogram

.

import matplotlib.pyplot as plt

# Data to plot
data = [(40, 1.646054384000001), (233, 3.0769193350000013), (221, 2.6460548819999996),
(214, 2.3542021680000005), (322, 2.726835301999998), (94, 1.201160183999999),
(193, 2.501363478000002), (171, 1.3009034040000031), (595, 5.574669749999998),
(248, 2.455411452)]

# Separate the data into two lists for word length and processing time
word_lengths = [d[0] for d in data]
processing_times = [d[1] for d in data]

# Plot the histogram
plt.hist(processing_times, bins=5)

# Add labels and title
plt.xlabel("Processing Time")
plt.ylabel("Frequency")
plt.title("Histogram of Processing Time")

# Show the plot
plt.show()

..


drawing graph

.

import matplotlib.pyplot as plt

# Data to plot
data = [(40, 1.646054384000001), (233, 3.0769193350000013), ..]

word_lengths = [d[0] for d in data]
processing_times = [d[1] for d in data]

plt.bar(word_lengths, processing_times)
plt.xlabel("Word Length")
plt.ylabel("Processing Time")
plt.title("Histogram of Word Lengths vs. Processing Times")
plt.show()

..



Thank you.πŸ™‡πŸ»‍♂️

www.marearts.com

No comments:

Post a Comment