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

Stem-Leaf and Box Plot Analysis

Uploaded by

VIDIT SHAH
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 views4 pages

Stem-Leaf and Box Plot Analysis

Uploaded by

VIDIT SHAH
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

Somaiya Vidyavihar University

(Constituent College – K J Somaiya College


of Engineering)

Problem statement:

1. Find Stem-Leaf plot for the following data and provide the key to
interpret the plot. 8.6, 2.5, 9.5, 7.3, 8.4, 2.1, 9, 2.5, 6.7, 7.1, 2.5, 9.4,
8.2, 2.1, 8.4, 7.5, 2.8, 7.2. 2.2
Ans :
Code:
import pandas as pd
import numpy as np
import [Link] as plt

# Data
data = [8.6, 2.5, 9.5, 7.3, 8.4, 2.1, 9, 2.5, 6.7, 7.1, 2.5, 9.4, 8.2, 2.1, 8.4, 7.5, 2.8, 7.2, 2.2]

# Create a stem-and-leaf plot


def stem_leaf_plot(data):
# Find the minimum and maximum values
min_val = int(min(data))
max_val = int(max(data))

# Create a dictionary to store the stem and leaf values


stem_leaf = {}
for num in data:
stem = int(num)
leaf = int((num - stem) * 10)
if stem not in stem_leaf:
stem_leaf[stem] = []
stem_leaf[stem].append(leaf)

# Print the stem-and-leaf plot


for stem in range(min_val, max_val + 1):
if stem in stem_leaf:
print(f"{stem} | {''.join(str(leaf) for leaf in stem_leaf[stem])}")

# Print the stem-and-leaf plot


stem_leaf_plot(data)

# Key: 2|1 represents 2.1

Output:
2 | 5155172
6|7
7 | 2052
8 | 5414
Somaiya Vidyavihar University
(Constituent College – K J Somaiya College
of Engineering)
9 | 504

Find Box plot for the following data and provide the key to interpret the plot. 23,
67, 62, 52, 23, 25, 33, 55, 58, 44, 33, 32, 29, 39, 31, 55, 66, 45, 41, 43, 36, 43,
41, 41, 62
Find the minimum, maximum, first quartile, third quartile and median values from the plot.

Implement program for any one of the above.

Flow chart/pseudo code:

Box Plot

Flow chart/pseudo code:

 Start
 Import Libraries: Import necessary libraries (NumPy, Matplotlib).
 Define Data: Store the dataset in a variable.
 Calculate Statistics:
 Sort the data.
 Compute:
o Minimum
o First Quartile (Q1)
o Median (Q2)
o Third Quartile (Q3)
o Maximum
 Create Box Plot: Use Matplotlib to create a box plot.
 Display Box Plot: Show the plot.
 Print Statistics: Output the calculated statistics.
 Interpret Plot: Analyze the box plot.
Somaiya Vidyavihar University
(Constituent College – K J Somaiya College
of Engineering)
Somaiya Vidyavihar University
(Constituent College – K J Somaiya College
of Engineering)
Results Analysis:

 Minimum (23): The lowest value in the dataset, shown as the leftmost whisker of
the box plot.
 First Quartile (Q1 = 36): This indicates that 25% of the data points are below 36,
represented by the left edge of the box.
 Median (Q2 = 41): The middle value of the dataset, where 50% of the data points are
below and 50% are above, indicated by the line inside the box.
 Third Quartile (Q3 = 55): This shows that 75% of the data points are below 55,
represented by the right edge of the box.
 Maximum (67): The highest value in the dataset, shown as the rightmost whisker of
the box plot.

Common questions

Powered by AI

Pseudo code and flowcharts serve as powerful tools for understanding and executing data visualization techniques by providing a clear, structured layout of the processes involved. Pseudo code offers a high-level description of the algorithm, delineating the logic without delving into the syntactical specifics of programming languages . Flowcharts provide a graphical representation of processes, allowing quick grasping of complex logic and interactions between steps in visualization creation. Together, they simplify collaborative efforts, guide troubleshooting, and facilitate the educational breakdown of complex data processes, ensuring clear comprehension before actual coding, thus reducing implementation errors.

Using coding libraries like Pandas and Matplotlib in data visualization facilitates efficient and precise computation and plotting of complex statistical graphs like stem-and-leaf and box plots . They automate processes such as sorting data, calculating quartiles, and plotting, which minimizes human error and significantly increases productivity, especially with large datasets. Additionally, these libraries provide advanced functionalities like handling data frames, direct data manipulation, high customization of plots, and integration with other data tasks in Python, which would be labor-intensive and error-prone if done manually. Automation also allows for easy updates and modification of plots as datasets change.

In a box plot, the minimum and maximum values are represented by the whiskers, which extend from the box's edges (Q1 and Q3) to the lowest and highest values within 1.5 times the interquartile range (IQR) from the quartiles . This helps identify the data range and detect potential anomalies or outliers that appear as points beyond the whiskers. Visualizing these extremes provides insights into the variability and spread of the dataset, indicating how dispersed it is or if there are significant deviations from the expected pattern.

A stem-and-leaf plot displays data by separating each value into a stem and a leaf, offering a way to retain individual data points within clusters, making it suitable for smaller datasets where individual data points are crucial . In contrast, a box plot summarizes data dispersion, showing quartiles, median, and potential outliers without detailing individual items, making it better for larger datasets or when a summary of the data distribution is desired. Stem-and-leaf plots excel in providing a quick, detailed look at small datasets, while box plots are preferred for their summarization capability when dealing with larger data volumes.

Separating data into integers (stems) and decimals (leaves) in stem-and-leaf plots offers a clear, organized way to visualize and analyze the data's distribution, maintaining all original data points . This separation aids in identifying patterns within data clusters, revealing local deviations or minor trends within the dataset with a granularity that might be lost in other plots. This helps in precisely reconstructing the data and examining data at finer resolutions, making it beneficial especially in analyzing small datasets that require attention to individual variability.

The key in a stem-and-leaf plot serves as a guide to interpreting the data's numeric value, functioning as a legend in graphical plots . For instance, the key '2|1' denotes that this stem-and-leaf representation corresponds to the numeric value 2.1. This clarifies how the leaves are attached to the stems, particularly crucial when the data span multiple magnitudes or involve decimal points, thus preventing misinterpretation and ensuring accurate data reading.

Creating a box plot involves the following steps: importing necessary libraries like NumPy and Matplotlib, defining the data set, sorting the data, and computing key statistics such as the minimum, first quartile (Q1), median (Q2), third quartile (Q3), and maximum. A box plot is then created using these statistics, where the box represents the interquartile range (IQR) between Q1 and Q3 with a line inside indicating the median. Whiskers extend to the minimum and maximum values, and outliers are displayed as individual points . This method illustrates data spread by showing the central tendency, variation, and skewness, and it easily identifies outliers.

Box plots are advantageous because they concisely display the distribution of data, central tendency, and variability without making any assumptions about the underlying statistical distribution . They effectively summarize large datasets and highlight outliers. However, box plots can be limited in revealing the precise distribution shape since they only display quartiles and median, potentially obscuring modes or the actual distribution within quartiles. They might not effectively convey subtle data features or nuances that histograms or kernel density plots might reveal. In large datasets, while box plots efficiently summarize data, the granular view and context of individual outlier points might not be visible.

Employing programmed solutions using Python libraries like Pandas and Matplotlib for data plots enhances scalability, allowing for the efficient handling of various dataset sizes and complexities . It ensures accuracy by systematically applying the same computational logic, thereby reducing human error. Moreover, it enables reproducibility across different data analyses since the code can be reused and adapted for new datasets, streamlining processes from initial data cleaning to final visualization. This systematic approach ensures consistency, facilitates version control, and enhances collaborative efforts by providing standard reproducible methodologies.

A stem-and-leaf plot organizes data by dividing each number into a stem, which is the integer part, and a leaf, which is the decimal or fractional part. For example, in the dataset provided, the number 2.5 is represented as '2 | 5' with '2' as the stem and '5' as the leaf . This visualization helps quickly identify the distribution, clusters, gaps, and outliers in a dataset. Compared to histograms, stem-and-leaf plots maintain the integrity of the original data and allow for quick retrieval of individual data points. They are particularly useful for small data sets but less effective for larger datasets compared to summaries like histograms or box plots that provide a more generalized overview.

You might also like