0% found this document useful (0 votes)
10 views3 pages

Python Data Visualization Lab Manual

The document outlines an experiment for students at Mahatma Gandhi Mission's College of Engineering and Technology, focusing on data visualization using Python. It includes objectives, source code for various plot types (line, scatter, bar, histogram, and pie charts), and a conclusion emphasizing the implementation of these programs. The experiment is part of the Computer Science and Engineering curriculum for the academic year 2024-25.

Uploaded by

shubham
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)
10 views3 pages

Python Data Visualization Lab Manual

The document outlines an experiment for students at Mahatma Gandhi Mission's College of Engineering and Technology, focusing on data visualization using Python. It includes objectives, source code for various plot types (line, scatter, bar, histogram, and pie charts), and a conclusion emphasizing the implementation of these programs. The experiment is part of the Computer Science and Engineering curriculum for the academic year 2024-25.

Uploaded by

shubham
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

‭Mahatma Gandhi Mission's College of Engineering and Technology‬

‭Department of Computer Science and Engineering (AIML &DS)‬

‭Academic Year 2024-25(Even Sem)‬

‭Experiment No. 10‬

‭Name of Student‬ ‭Shyamdin Prajapati‬

‭Roll No‬ ‭55‬

‭DOP‬ ‭DOS‬ ‭Marks/Grade‬ ‭Signature‬

‭ im:‬‭Write python programs to understand Data visualization‬


A
‭Objective:‬ ‭∙ To study Data visualization using python.‬
‭Outcome:‬‭Students will be able to understand Data visualization.‬

‭i) WAP to implement different types of plots using Numpy and Matplotlob‬

‭Source Code:‬

i‭mport numpy as np‬


‭import [Link] as plt‬

#‭ Line plot with two datasets‬


‭x = [1, 2, 3, 4, 5]‬
‭y1 = [1, 4, 9, 16, 25]‬
‭y2 = [2, 3, 5, 7, 11]‬
‭[Link](figsize=(6, 5))‬
‭[Link](x, y1, color='green', linestyle='-', marker='o', label='Dataset 1')‬
‭[Link](x, y2, color='red', linestyle='--', marker='s', label='Dataset 2')‬
‭[Link]('X-axis')‬
‭[Link]('Y-axis')‬
‭[Link]('Simple Plot with Two Datasets')‬
‭[Link]()‬
‭[Link]('Point‬ ‭(3,‬ ‭9)',‬ ‭xy=(3,‬ ‭9),‬ ‭xytext=(4,‬ ‭10),‬ ‭arrowprops=dict(facecolor='blue',‬
‭arrowstyle='->'))‬
‭[Link]()‬

#‭ Scatter plot example‬


‭x = [1, 2, 3, 4, 5]‬
‭y = [1, 4, 9, 16, 25]‬
‭[Link](x, y, color='blue', marker='o', label='Dataset')‬
‭[Link]('X-axis')‬
‭[Link]('Y-axis')‬
‭[Link]('Simple Scatter Plot')‬
‭[Link]()‬
‭[Link]()‬

#‭ Bar chart example‬


‭categories = ['Uttar Pradesh', 'Maharashtra', 'Bihar', 'West Bengal', 'Madhya Pradesh']‬
‭LAB MANUAL [IV --- Python Lab] Page‬‭26‬
‭Mahatma Gandhi Mission's College of Engineering and Technology‬

‭Department of Computer Science and Engineering (AIML &DS)‬

‭Academic Year 2024-25(Even Sem)‬

v‭ alues = [199.8, 123.1, 124.8, 99.6, 85.3]‬


‭[Link](figsize=(6, 5))‬
‭[Link](categories, values, color='green')‬
‭[Link]('Bar Chart: Indian States vs Population (in millions)')‬
‭[Link]('States of India')‬
‭[Link]('Population (in millions)')‬
‭[Link]()‬

#‭ Histogram example‬
‭data = [Link](1000)‬
‭[Link](figsize=(6, 5))‬
‭[Link](data, bins=30, color='lightblue', edgecolor='black')‬
‭[Link]('Histogram: Distribution of Random Data')‬
‭[Link]('Value')‬
‭[Link]('Frequency')‬
‭[Link](True)‬
‭[Link]()‬

#‭ Pie chart example‬


‭labels = ['Python', 'Java', 'C++', 'JavaScript', 'Ruby']‬
‭sizes = [40, 25, 15, 10, 10]‬
‭colors = ['lightcoral', 'lightskyblue', 'lightgreen', 'lightgoldenrodyellow', 'lavender']‬
‭[Link](figsize=(5, 5))‬
‭[Link](sizes, labels=labels, autopct='%1.1f%%', startangle=140, colors=colors)‬
‭[Link]('Programming Language Usage in Software Project', pad=20)‬
‭[Link]('equal')‬
‭plt.tight_layout()‬
‭[Link]()‬

‭OUTPUT:‬

‭LAB MANUAL [IV --- Python Lab] Page‬‭27‬


‭Mahatma Gandhi Mission's College of Engineering and Technology‬

‭Department of Computer Science and Engineering (AIML &DS)‬

‭Academic Year 2024-25(Even Sem)‬

‭Conclusion: In this way we implemented python programs to understand Data visualization‬


‭LAB MANUAL [IV --- Python Lab] Page‬‭28‬

Common questions

Powered by AI

Implementing a variety of plot types in a Python data visualization program allows users to derive insights related to data distribution, relationships, and comparisons across categories. For instance, line plots help in understanding trends over sequences, scatter plots depict relationships between variables, bar charts compare categorical data, histograms display the distribution of datasets, and pie charts show proportions within a whole. This diversity in visualization techniques enables comprehensive data analysis and fosters better decision-making .

Using Python libraries like NumPy and Matplotlib enhances the understanding of data visualization techniques by providing powerful tools for creating a variety of plots and charts. NumPy aids in efficient data manipulation, while Matplotlib offers comprehensive features for visual representation. For example, Matplotlib can create line plots, scatter plots, bar graphs, and pie charts, enabling users to visually interpret data trends and patterns clearly and effectively .

The 'autopct' parameter in Matplotlib's pie chart function serves the purpose of displaying percentages on each slice of the pie chart. It formats the percentage labels according to a specified string format, such as '%1.1f%%', which ensures that the percentages are shown with one decimal place. This feature provides immediate, clear insight into how each portion's size relates to the whole, enhancing the pie chart's readability and interpretative power .

Pie charts are beneficial for representing data distributions where the focus is on showcasing proportions of a whole, such as market share or demographic breakdowns. They provide an immediate visual impact for comparing parts to a whole. However, pie charts can be limited in conveying complex data efficiently, as they are less effective in showing small differences between segments or when dealing with a large number of categories. This can lead to a lack of clarity or misinterpretation if the differences are subtle or not distinctly visible .

The figure size parameter in Matplotlib is significant as it determines the dimensions of the plot in inches, thereby affecting the readability and visual impact of graphs. A well-configured figure size ensures that elements such as labels, titles, and data points are clear without overcrowding, enhancing the audience's comprehension. It is crucial for effectively presenting results where screen space and resolution may vary .

The choice of plot type for visualizing data is influenced by factors such as the data's nature and dimensionality, the specific relationships to be highlighted, and the intended audience's needs. For example, time series data is best represented with line plots, while categorical comparisons are well-suited to bar charts. Scatter plots exhibit relationships and variances between two variables, histograms illustrate distribution, and pie charts are effective for showing proportions. Data complexity and the requirement for interactive or static representation also play vital roles in determining the appropriate plot .

The use of gridlines in Matplotlib plots contributes to data interpretation by providing a reference framework that makes it easier to align and visually track data points across axes. This structural aid enhances the user's ability to accurately assess the magnitude and relationships in the data. Gridlines help viewers relate specific values to grid sections, improving precision in analysis without cluttering the chart .

Annotations in data visualizations mark specific data points or areas with additional context, enhancing clarity and usefulness. By highlighting particular points, such as peaks or outliers in a dataset, annotations help the viewer easily identify key elements without misinterpretation. They guide the analysis by providing precise references, such as in a plot of y = x^2 where the maximum point is annotated, improving the narrative quality of data presentation .

Using different colors for datasets in the same plot is important to distinguish between multiple data series easily, preventing confusion and helping in quick pattern recognition. When choosing colors, one must consider factors like accessibility for color-blind individuals, the ability of the colors to contrast well with the background, and the use of a consistent palette that reflects the data context (e.g., using red and green for opposite signals). Good color choices enhance both aesthetics and functional readability of the visualizations .

Random data generation using NumPy is instrumental in simulating real-world data by creating sample datasets for testing and validating data visualization scenarios. This practice assists in understanding how visualizations might appear with actual data patterns, particularly when access to comprehensive datasets isn't feasible. It allows experimentation with various data distributions and helps in refining visualization techniques before applying them to true datasets, thereby building a robust foundation for analysis .

You might also like