16 Mark Ds
16 Mark Ds
https://youtu.be/YUGq8e5JIOI?si=2wfBk_gisuT6OAzX
3
import pandas as pd
import numpy as np
4
import pandas as pd
OUTPUT
X Y Z
0 78 84 86
1 85 94 97
2 96 89 96
3 80 83 72
4 86 86 83
5
import numpy as np
OUTPUT
Unique elements of the array:
[1 2 3 4 5 6 7 8 9]
6
import numpy as np
OUTPUT
Set difference between the two arrays:
[1 2 3]
7
Matplotlib is a popular Python library used for creating static, animated, and interactive
visualizations in a variety of formats. It provides a flexible platform for generating plots,
charts, and graphs, making it widely used in data analysis and scientific computing.
2. Object-Oriented Interface: This approach gives more control over the figure and axes
objects, allowing for greater customization and flexibility. It is more suitable for complex plots
and when integrating Matplotlib with other libraries or frameworks.
Both interfaces can be used together, depending on the specific needs of the user.
8
Line Plot
A line plot is a graphical representation that connects individual data points with straight
lines. It is widely used in data visualization to depict trends over time or relationships
between variables. The main characteristics of line plots include:
1. Axes:
The x-axis typically represents the independent variable, such as time or categories.
The y-axis represents the dependent variable, showing how it changes with respect to the
x-axis.
2. Data Points:
Each point on the plot corresponds to a data value. Points are plotted based on their x and y
coordinates.
3. Trend Visualization:
Line plots are effective for visualizing trends, as the connected points highlight the
progression or change of data over intervals.
4. Multiple Lines:
Multiple datasets can be plotted on the same graph, allowing for easy comparison between
different groups or conditions.
5. Use Cases:
Commonly used in time series analysis, financial data, and any context where changes over
time need to be illustrated.
Scatter Plot
A scatter plot displays individual data points on a two-dimensional plane, showing the
relationship between two quantitative variables. It is particularly useful for identifying
patterns, correlations, and distributions in data. Key aspects of scatter plots include:
1. Axes:
The x-axis represents one variable, while the y-axis represents another variable.
2. Data Representation:
Each dot represents an observation, with its position determined by the values of the two
variables being plotted.
3. Correlation Identification:
Scatter plots can reveal the nature of the relationship between variables (positive, negative,
or no correlation) by examining the overall pattern of the points.
4. Outliers:
They are useful for spotting outliers—points that fall far away from the general cluster of
data.
5. Use Cases:
Commonly used in statistics, research, and various scientific fields to assess relationships,
such as between height and weight or temperature and sales.
Comparison
Purpose: Line plots emphasize trends over time, while scatter plots focus on relationships
between two variables.
Data Type: Line plots are typically used for continuous data, whereas scatter plots can
handle both continuous and discrete data.
Visualization: Line plots connect data points to illustrate a flow, while scatter plots display
points independently, emphasizing their distribution.
Conclusion
Both line plots and scatter plots are essential tools in data analysis and visualization.
Understanding their strengths and applications enables effective communication of insights
derived from data, aiding in decision-making across various fields.
9
import numpy as np
OUTPUT
Appended array:
[ 1 2 3 4 5 6 7 8 9 10]
10
import numpy as np
Output
Floating array:
[1. 2. 3. 4. 5.]
11
import numpy as np
12
Repeated of 5
First, ensure you have Matplotlib installed. If not, you can install it using pip:
You can add simple text to your plots using the text() function. This function allows you to
specify the exact location for the text.
Example of Adding Text
# Sample data
x = [1, 2, 3, 4]
y = [10, 15, 7, 10]
plt.show()
Explanation:
3. Annotating Points
Annotations provide context to specific data points, often with an arrow pointing to the point
of interest. This is done using the annotate() function.
# Sample data
x = [1, 2, 3, 4]
y = [10, 15, 7, 10]
plt.show()
Explanation:
You can further customize text and annotations using various parameters.
# Sample data
x = [1, 2, 3, 4]
y = [10, 15, 7, 10]
plt.plot(x, y)
plt.title('Customized Text and Annotations')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
Explanation:
bbox: Adds a background box to the text with specified properties like facecolor and alpha
(transparency).
arrowprops: Further customize the arrow's color and style.
You can also change the font properties and styles of the text and annotations.
# Sample data
x = [1, 2, 3, 4]
y = [10, 15, 7, 10]
plt.plot(x, y)
plt.title('Font Customization in Annotations')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
14
Importing Required Libraries
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.show()
Explanation:
scatter(): Creates a scatter plot with specified color and marker style.
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Explanation:
np.linspace(0, 1, 100): Generates 100 evenly spaced values between 0 and 1 for z.
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.show()
Explanation:
np.meshgrid(): Creates a rectangular grid out of two given one-dimensional arrays (x and y).
A wireframe plot is a 3D representation of the surface using lines instead of solid colors.
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.show()
Explanation:
15
Repaeted of 1
16
Repeated Of 10
17
import numpy as np
Output
Reversed array:
[9 8 7 6 5 4 3 2 1]
18
Repeated of 12 and 5
19
Repaeted Of 6
20
1. Understanding Geographic Data
Geographic data refers to information that is associated with specific locations on the Earth.
This data can include:
Geographic data is often represented in coordinate systems, commonly using latitude and
longitude for positioning.
2. Base Maps
A base map provides context for the geographic data being displayed. It can be a simple
outline of geographical features, or it can include detailed representations of terrain, roads,
and labels.
Matplotlib with Basemap: Provides simple visualizations with customizable base maps.
GeoPandas extends the capabilities of Pandas to allow for spatial operations on geometric
types. Here’s how to use it to visualize geographic data with a base map.
Installation
You can load geographic data from various sources. For example, GeoPandas comes with
built-in datasets like the world countries shapefile.
You can overlay additional data on the base map. For instance, let’s visualize country
populations.
Make sure the data is available in a suitable format, such as a CSV file. You can merge this
data with the geographic dataset based on a common key (like country names).
population_df = pd.DataFrame(population_data)
2. Merge DataFrames
You can customize the base map using different styles, layers, and additional features.
Using other libraries such as contextily, you can add tiled web maps (like OpenStreetMap)
for more context.
# Add a basemap
ctx.add_basemap(ax, crs=world.crs.to_string())
plt.title('World Population with Base Map')
plt.show()
21
1. Line Plot
A line plot displays data points connected by lines, making it ideal for showing trends over
time.
# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
2. Scatter Plot
A scatter plot visualizes the relationship between two numerical variables using points.
# Sample data
x = np.random.rand(50)
y = np.random.rand(50)
3. Bar Chart
Bar charts are used to compare quantities across different categories.
# Sample data
categories = ['A', 'B', 'C', 'D']
values = [4, 7, 1, 8]
4. Histogram
# Sample data
data = np.random.randn(1000)
5. Box Plot
Box plots summarize the distribution of a dataset based on five statistics: minimum, first
quartile, median, third quartile, and maximum.
6. 3D Plot
Matplotlib can also handle three-dimensional data visualization, useful for complex datasets.
# Sample data
x = np.random.rand(100)
y = np.random.rand(100)
z = np.random.rand(100)