Statement of Completion#5007c9d2
Visualizations with Matplotlib
easy
Introduction to Data Visualization and Matplotlib Basics
Resolution
Activities
Project.ipynb
Introduction to Data Visualization¶
Import Matplotlib Correctly
In [1]:
import matplotlib.pyplot as plt
Use Subplots for Multiple Plots¶
In [2]:
fig, axs = plt.subplots(2, 2) # Create a 2x2 grid of subplots
Customize Plot Appearance¶
In [3]:
x=[1,2,3,4]
y=[5,6,7,8]
plt.plot(x, y, color='blue', linestyle='--', marker='o', label='Data')
plt.xlabel('X-axis Label')
plt.ylabel('Y-axis Label')
plt.title('Customized Plot')
plt.legend()
Out[3]:
<matplotlib.legend.Legend at 0x780044466f50>
Save High-Quality Images¶
In [4]:
plt.savefig('plot.png', dpi=300, bbox_inches='tight')
<Figure size 640x480 with 0 Axes>
Utilize Colormaps¶
The values of z
to [1, 2, 3, 5]
will affect the colors of the points in the scatter plot. Each value in z corresponds to a data point, determining its color based on the colormap specified.
In [5]:
z = [1,2,3,4]
plt.scatter(x, y, c=z, cmap='viridis')
Out[5]:
<matplotlib.collections.PathCollection at 0x7800394dbcd0>
In this case, the colormap viridis
will map the values in z to colors. The specific colors will depend on the values in z and how they are distributed relative to the colormap.
Annotate and Add Text¶
In [6]:
plt.annotate('This point is interesting!', xy=(2, 6))
Out[6]:
Text(2, 6, 'This point is interesting!')
Using plt.show()
¶
In [7]:
x=[1,2,3,4]
y=[5,6,7,8]
# Create and customize your plot
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Interactive Plot')
# Display the plot interactively
plt.show()
"No show()": Generating Static Images¶
In [8]:
# Create and customize your plot
plt.plot(x, y)
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Static Plot')
# Save the plot as an image (e.g., PNG)
plt.savefig('static_plot.png', dpi=300, bbox_inches='tight')