** What you can do by reading this article **
matplotlib allows you to insert a partially enlarged view into the same plot
I wanted to draw this kind of guy.
--Environment - macOS mojave 10.14.6 - Python 3.7.6
With simple steps that do nothing All you have to do is prepare a frame for the subplot.
zoom.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.tick_params(which='both', direction='in', top=bool, right=bool, labelbottom=True)
ax1.set_xlim(0.0, 4.0)
ax1.set_xlabel("x")
ax1.set_ylim(0, 2)
ax1.set_ylabel("y")
#Creating a function
x = np.arange(0.01, 4.0, 0.01)
y = x*x*np.sin(1.0/(x*x*x)) +0.4
ax1.plot(x, y, "-", color='red', lw=1)
#Position of subplot to zoom
#axes([How far away from the left,How far away from the bottom,width,height])
sub_axes = plt.axes([.2, .6, .25, .25])
sub_axes.tick_params(which='both', direction='in', top=bool, right=bool, labelbottom=True)
sub_axes.tick_params(labelsize=7)
sub_axes.grid(which='major',color='gray',alpha=0.1,linestyle=':',linewidth=0.3)
sub_axes.set_xlim(0.0, 0.6)
sub_axes.set_xticks( [0, 0.2, 0.4, 0.6] )
sub_axes.set_ylim(0.0, 0.8)
#Draw a subplot
sub_axes.plot(x, y)
plt.savefig("zoom.eps")
reference: How to zoom a part of an image and insert it into the same plot in matplotlib
Recommended Posts