[PYTHON] Make a partially zoomed figure with matplotlib

** 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. zoom.png

--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

Make a partially zoomed figure with matplotlib
Make a fortune with Python
Make a fire with kdeplot
Make a gif animation from a serial number file with matplotlib
Let's make a GUI with python.
Make a sound with Jupyter notebook
Draw a loose graph with matplotlib
Let's make a breakout with wxPython
Make a recommender system with python
Make a filter with a django template
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Make a model iterator with PySide
Make a nice graph with plotly
Write a stacked histogram with matplotlib
Let's make a shiritori game with Python
Make a video player with PySimpleGUI + OpenCV
Try drawing a normal distribution with matplotlib
Make a rare gacha simulator with Flask
Make a Notebook Pipeline with Kedro + Papermill
Make a drawing quiz with kivy + PyTorch
Let's make a voice slowly with Python
Make a cascade classifier with google colaboratory
Let's make a simple language with PLY 1
[Python] Let's make matplotlib compatible with Japanese
Make a logic circuit with a perceptron (multilayer perceptron)
Make a Yes No Popup with Kivy
Make a wash-drying timer with a Raspberry Pi
Make a GIF animation with folder monitoring
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Match the colorbar to the figure with matplotlib
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Make matplotlib look like a flat design
Write a nice pie chart with matplotlib
Let's make a web framework with Python! (2)
Make common settings with subplot of matplotlib
Create a graph with borders removed with matplotlib
I want to make matplotlib a dark theme
A memo for making a figure that can be posted to a journal with matplotlib
Draw a flat surface with a matplotlib 3d graph
A memorandum to make WebDAV only with nginx
Investment quest: Make a system trade with pyhton (2)
Make a Twitter trend bot with heroku + Python
[Python] Make a game with Pyxel-Use an editor-
Make a monitoring device with an infrared sensor
Make a simple pixel art generator with Flask
Investment quest: Make a system trade with pyhton (1)
How to make a dictionary with a hierarchical structure.
I want to make a game with Python
Make a histogram for the time being (matplotlib)
Try to make a "cryptanalysis" cipher with Python
[Python] Make a simple maze game with Pyxel
Animation with matplotlib
Let's replace UWSC with Python (5) Let's make a Robot
Japanese with matplotlib
Draw a graph with matplotlib from a csv file
Try to make a dihedral group with Python
[Chat De Tornado] Make a chat using WebSocket with Tornado
Animation with matplotlib