- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to zoom a portion of an image and insert in the same plot in Matplotlib?
To zoom a portion of an image and insert in the same plot, we can take the following steps −
Create x and y points, using numpy.
To zoom a part of an image, we can make data for x and y points, in that range.
Plot x and y points (Step 1), using the plot() method with lw=2, color red and label.
Use the legend() method to place text for the plot, Main curve.
Create the axes using the axes() method by putting the rectangle’s coordinate.
Plot x and y points (Step 2), using the plot() method with lw=1, color='green' and label, i.e., subpart of the plot.
Use the legend() method to place text for the plot, zoomed curve.
To display the figure, use the show() method.
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-5, 5, 1000) y = np.sin(x) x_zoom = np.linspace(-1, 1, 50) y_zoom = np.sin(x_zoom) plt.plot(x, y, c='red', lw=2, label="Main curve") plt.legend() axes = plt.axes([.30, .6, .20, .15]) axes.plot(x_zoom, y_zoom, c='green', lw=1, label="Zoomed curve") axes.legend() plt.show()
- Related Articles
- How to insert a small image on the corner of a plot with Matplotlib?
- How to plot an animated image matrix in matplotlib?
- How to plot a watermark image in Matplotlib?
- How to plot a layered image in Matplotlib in Python?
- How to apply pseudo color schemes to an image plot in Matplotlib?
- How to name different lines in the same plot of Matplotlib?
- Matplotlib – Plot over an image background in Python
- How to show a bar and line graph on the same plot in Matplotlib?
- How to Zoom with Axes3D in Matplotlib?
- Matplotlib – How to insert a degree symbol into a Python plot?
- How to use a custom png image marker in a plot (Matplotlib)?
- How to zoom subplots together in Matplotlib/Pyplot?
- How to set same color for markers and lines in a Matplotlib plot loop?
- How to Insert an Image in HTML Page?