Exhibit 25.57 provides an example of drawing a line from (1, 3) to (8, 10), using matplotlib.
import matplotlib.pyplot as plt
import numpy as np
# Create arrays for x and y points
xpoints = np.array([1, 8])
ypoints = np.array([3, 10])
# Generate the plot
plt.plot(xpoints, ypoints)
# Add labels and title for clarity
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Line from (1, 3) to (8, 10)")
# Display the plot
plt.show()
NumPy is a Python library designed for efficient handling of multi-dimensional arrays. It is derived from “Numerical Python” and offers a powerful tool for array manipulation and numerical operations.
While Python lists can be used as arrays, they can be relatively slow for large-scale numerical computations. NumPy addresses this by providing the ndarray
object, which is optimized for speed and memory efficiency. This, combined with NumPy’s rich set of functions, makes it ideal for data science tasks that require efficient array processing.
As shown in Exhibit 25.57, a NumPy ndarray
object, can be generated use the array()
function. The code creates two NumPy arrays, xpoints and ypoints, holding the x and y coordinates of the data points. The plt.plot()
function then uses these arrays to generate the line plot. Finally, labels and a title are added for better understanding, and plt.show()
displays the plot.
Use the Search Bar to find content on MarketingMind.
Contact | Privacy Statement | Disclaimer: Opinions and views expressed on www.ashokcharan.com are the author’s personal views, and do not represent the official views of the National University of Singapore (NUS) or the NUS Business School | © Copyright 2013-2025 www.ashokcharan.com. All Rights Reserved.