0% found this document useful (0 votes)
32 views1 page

Data Visualization with Python Charts

The document contains Python code for creating three types of visualizations using Matplotlib. It includes a pie chart representing modes of transportation, a scatter chart visualizing rainfall data for Tamil Nadu from a CSV file, and a histogram displaying the heights of girls in class XII. Each visualization is accompanied by relevant labels, titles, and formatting to enhance clarity.

Uploaded by

sdg
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)
32 views1 page

Data Visualization with Python Charts

The document contains Python code for creating three types of visualizations using Matplotlib. It includes a pie chart representing modes of transportation, a scatter chart visualizing rainfall data for Tamil Nadu from a CSV file, and a histogram displaying the heights of girls in class XII. Each visualization is accompanied by relevant labels, titles, and formatting to enhance clarity.

Uploaded by

sdg
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

# Write a program to create pie chart on the given data.

import [Link] as pl
labels = ["Car","Public Transit", "Walking", "Bicycle"]
sizes = [40,30,20,10]
colors=['green','c','lightgreen','yellow']
[Link](figsize=(6,6))
[Link](sizes,labels=labels,colors=colors,autopct='%1.1f%%')
[Link]('Equal')
[Link]("Mode of Transportaion")
[Link]()

#Write a program to draw a scatter chart to visualize the comparative rainfall data for 12 months in
Tamil Nadu using the CSV file "[Link]".

import numpy as np
import pandas as pd
import [Link] as plt
df=pd.read_csv("[Link]")
x=df ['Months']
y=df['Rainfall']
[Link](figsize=(5,3))
[Link](figsize=(6,4))
colors = [Link]([0, 10, 20, 30, 40, 45, 50, 60, 70, 80, 90, 100])
[Link](x,y,c=colors,cmap='viridis')
[Link]("Rainfall data of Tamil Nadu", fontname='Calibri',
color='m',fontsize=16)
[Link](rotation = 45)
[Link]("Months", fontname='Calibri', color='b',fontsize=12)
[Link]("Rainfall (cm)", fontname='Calibri', color='b',fontsize=12)
[Link]()

#Write a program to create histogram on the given data.

import [Link] as pl
a=[141, 145, 142, 147, 144, 148, 141, 142, 149, 144, 143, 149, 146,
141, 147, 142, 143]
[Link]("Number of Girls")
[Link]("Height")
[Link](" Heights of Girls in class-XII")
[Link](a)
[Link]()

Common questions

Powered by AI

Histograms represent data distributions by displaying the frequency of data within certain intervals, allowing for the visualization of the central tendency, spread, and shape of a dataset. In the histogram of class-XII girls' heights, it can provide insight into the most common height range, variability, and whether the data distribution is symmetric, skewed, or contains any outliers. For instance, if most girls fall into a similar height range, it indicates that the data is tightly clustered, showing a central tendency and possibly normal distribution .

Pandas facilitates the creation of visualizations in Python by providing flexible and efficient manipulation of structured data through DataFrames, which can easily interface with visualization libraries like Matplotlib. In the examples, pandas is used to read and structure rainfall data from a CSV file into a DataFrame, which allows easy selection and plotting of columns for visualization. This integration enables dynamic and versatile plotting, allowing users to directly plot pandas DataFrame objects or series, streamline data processing, and enhance visualization tasks .

Representing transport modes in terms of percentages, as shown in the pie chart, is useful because it provides a clear, proportional comparison of the different modes. This percentage representation makes it easy to understand the relative contributions of each mode at a glance, facilitating decision-making and communication among stakeholders. It enables quick identification of dominant or underutilized transport modes, thereby aiding in strategic planning, policy-making, or the allocation of resources, and helps in assessing the impact of various transportation policies .

The scatter plot uses a color map ('viridis') to enhance visual comprehension by assigning different colors to the points based on another variable, in this case, the index or a custom array. This method allows viewers to quickly distinguish differences and patterns across different months, enhancing both the aesthetic nature and interpretative power of the chart. The use of a color map can highlight trends or anomalies that may not be evident from the positions of points alone, thereby aiding in the identification of data patterns or clusters .

CSV files play a crucial role in data visualization by providing a standardized format for storing and transferring tabular data, which can be easily read into programming environments like Python. In the scatter plot example, the CSV file 'rainfall.csv' contains monthly rainfall data for Tamil Nadu, which is read using the pandas library into a DataFrame format for subsequent analysis and visualization with Matplotlib. This allows for seamless integration of external data into visualization workflows, enabling analysts to manipulate, process, and visually present data efficiently .

Setting an equal aspect ratio when plotting a pie chart is crucial for accurately representing the data proportions. By using 'pl.axis('Equal')', the chart ensures that the pie slices reflect the intended proportionate sizes, preventing distortion that can occur when the axis limits allow stretching or squashing of the chart. This equalization maintains visual consistency and allows for accurate interpretation of relative sizes among different categories, ensuring the chart accurately communicates the data distribution, in this case, of transportation modes .

When choosing the size and resolution of a figure in data visualization using Matplotlib, considerations include the complexity and density of the information being displayed, the intended medium for dissemination, and the need for clarity and readability. For example, the size of (6,6) for the pie chart and (6,4) for the scatter plot was selected likely to ensure that there is sufficient space to display all elements clearly without overlap and allowing labels to be legible. Adjusting figure size can also help avoid overcrowding of data points, enhance aesthetics, and ensure the chart fits well on different viewing platforms or publications .

The programming library used is Matplotlib, specifically through the 'pyplot' module, which allows for the creation of various visual charts such as pie charts, scatter plots, and histograms. In the examples provided, it is used to create a pie chart illustrating modes of transportation, a scatter plot visualizing comparative monthly rainfall data in Tamil Nadu from a CSV file, and a histogram showing the distribution of heights of girls in class XII. This demonstrates Matplotlib's capability to handle diverse forms of data visualization, including categorical data, continuous data over time, and frequency distributions .

The pie chart shows that public transportation accounts for 30% of the total transport modes, indicating its significant role in the commuting patterns among the given population. Understanding this distribution is important as it helps policymakers and urban planners assess the reliance on and effectiveness of different transport modes, informing decisions related to infrastructure development, sustainability, and resource allocation. It also reflects societal trends and can drive initiatives to promote or improve particular transportation modes .

Rotating the x-axis labels in the scatter plot of the Tamil Nadu rainfall data, as indicated by 'plt.xticks(rotation=45)', is necessary to improve readability of the labels. With long text such as month names or crowded labels, reading the x-axis becomes difficult if they are not rotated or adjusted. Rotating them helps in maintaining a clean layout and ensures that the labels do not overlap or become truncated, which is essential for accurate data interpretation and professional presentation of data visualizations .

You might also like