Introduction
Enhancing statistical plots helps make data easier to understand and more visually appealing.
Jump into concepts and practice - no test required
Enhancing statistical plots helps make data easier to understand and more visually appealing.
import matplotlib.pyplot as plt plt.plot(data) plt.title('Title') plt.xlabel('X-axis label') plt.ylabel('Y-axis label') plt.grid(True) plt.legend(['Label']) plt.show()
plt.title() to add a title to your plot.plt.xlabel() and plt.ylabel() to label axes.plt.plot([1, 2, 3], [4, 5, 6]) plt.title('Simple Line Plot') plt.show()
plt.plot([1, 2, 3], [4, 5, 6], color='red', linestyle='--') plt.grid(True) plt.show()
plt.plot([1, 2, 3], [4, 5, 6], label='Data 1') plt.legend() plt.show()
This program plots prime numbers with green circles connected by lines. It adds a title, axis labels, grid lines, and a legend for clarity.
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [2, 3, 5, 7, 11] plt.plot(x, y, marker='o', color='green', linestyle='-', label='Prime Numbers') plt.title('Prime Number Growth') plt.xlabel('Index') plt.ylabel('Value') plt.grid(True) plt.legend() plt.show()
Use markers like 'o', 's', '^' to highlight points on the plot.
Grid lines help viewers read values more easily.
Legends are important when plotting multiple data sets.
Enhancements make plots clearer and more informative.
Titles, labels, grids, and legends improve understanding.
Colors and styles help highlight key data.
legend to a matplotlib plot?plt.title().plt.title('My Plot'), which is correct syntax.import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], marker='o', color='red')
plt.grid(True)
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.title('Sample Plot')
plt.show()import matplotlib.pyplot as plt plt.plot([1, 2, 3], label='Line 1') plt.legend() plt.show()
plt.scatter() with marker='^' and color='blue'.plt.grid(True), and axes labeled 'Height' and 'Weight' correctly.