Matplotlib — Basic Plotting

Exhibit 25.57 provides an example of drawing a line from (1, 3) to (8, 10), using matplotlib.

Matplotlib — Plotting a Basic Line Chart
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()
    Matplotlib - Plotting a line chart    

Exhibit 25.57 Matplotlib — Plotting a basic line chart. Jupyter notebook.

The code in Exhibit 25.57 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.


Previous     Next

Use the Search Bar to find content on MarketingMind.