Plot 2d array Python
In this post, you will learn how to generate 2D array plot using the Python Matplotlib.
A plot can present the data in continuous, discrete, surface, or volume form. Matplotlib was initially designed with only two-dimensional plotting in mind. In the release of 1.0 version, the three-dimensional plotting utilities were built on top of Matplotlib's two-dimensional display, and the result is helpful for three-dimensional data visualization.
A two-dimensional (2D) array is utilised to contain different arrays that hold values. The components of a 2D array are stored in column and row wise like a table or matrix.
Matplotlib plot numpy array 2d
In the given example, first we import the necessary modules and define the data coordinates x and y and then use the plot() method to plot the 2D numpy array.
# Import Library
import numpy as np
import matplotlib.pyplot as plt
# Defining Data
x = np.array([[4, 7, 9], [8, 10, 12]])
y = np.array([[10, 12, 14], [16, 18, 20]])
# Plot
plt.plot(x, y)
# Display
plt.show()
Output of the above code:
Matplotlib scatter plot numpy array 2d
import numpy as np
from matplotlib import pyplot as plt
# Set the figure size
plt.rcParams["figure.figsize"] = [7.25, 4.25]
plt.rcParams["figure.autolayout"] = True
# Random data of 100×3 dimension
data = np.array(np.random.random((100, 3)))
# Scatter plot
plt.scatter(data[:, 0], data[:, 1], c=data[:, 2], cmap='hot')
# Display the plot
plt.show()
Output of the above code:
Matplotlib scatter plot numpy array 2d as image
import numpy as np
import matplotlib.pyplot as plt
# Define Data
x = np.array([[[0, 0, 60],
[120, 120, 0],
[60, 0, 0]],
[[0, 0, 120],
[255, 255, 0],
[120, 0, 0]],
[[0, 255, 0],
[0, 0, 255],
[255, 0, 255]]])
# Image
plt.imshow(x)
# Display
plt.show()
Output of the above code:
Related Articles
Simple Matplotlib Animation ExampleMatplotlib Pie Chart
Python Line Plot Using Matplotlib
Python Matplotlib Bar Plot
How to save figure in matplotlib pyplot
Python Matplotlib Scatter Plot
Python Pandas Plotting
How to capture a video in Python OpenCV and save
Python OpenCV Overlaying or Blending Two Images
Contour Detection using Python OpenCV
Harris Corner Detection using Python OpenCV
Human detection OpenCV
Face Recognition OpenCV Source Code
Canny Edge Detector OpenCV Python
Python NumPy: Overview and Examples
Image processing using Python Pillow
Python OpenCV Histogram Equalization
Python OpenCV Histogram of Color Image
Python OpenCV Histogram of Grayscale Image
Python OpenCV Image Filtering
Python OpenCV ColorMap
Python OpenCV Gaussian Blur Filtering
Python OpenCV Overview and Examples