Inset axes anchored to specific points in data coordinates?

2024/9/20 0:04:20

I'd like to be able to overlay multiple inset axes on top of a set of parent axes, something like this:

enter image description here

Ideally, I'd like the anchor point of each set of inset axes to be fixed in data coordinates, but for the x,y extent of the axes to scale with figure size rather than the scale of the data.

For example, if I zoomed in on a region in the parent axes, I'd want the positions of the inset axes to move together with the data plotted in the parent axes, but for their areas and aspect ratios to stay the same. The exact behaviour I'm looking for is something similar to a plot marker or a matplotlib.Annotation instance. However, I'd settle for just being able to set the extent of the axes in data coordinates.

I'm aware that I can pass the rect argument to axes() to specify the position and extent in normalized figure coordinates. However, I need my axes to be anchored to specific points in data coordinates.

I've also tried doing something like this:

from matplotlib import pyplot as ppfig,parent_ax = pp.subplots(1,1)
parent_ax.set_xlim(0,1)
parent_ax.set_ylim(0,1)# desired axis bounding box in data coordinates
rect = (0.1,0.2,0.2,0.3)child_ax = axes(rect)# apply transformation to data coordinates of parent axis
child_ax.set_transform(parent_ax.transData)

which doesn't have the desired effect (the x,y limits of my child axis are now coupled to those of the parent axis, which I don't want, and its position is still not in data coordinates).

I've also looked at the various examples here, but none of them seem to do quite what I'm looking for, i.e. allow me to specify an arbitrary anchor point in data coordinates.

Any ideas?

Answer

Save the inset axes as images and then insert them in the larger figure. See Adding a small photo/image to a large graph in Matplotlib/Python .

https://en.xdnf.cn/q/72749.html

Related Q&A

No module named folium.plugins, Python 3.6

I am trying to import folium into a Jupyter notebook Im working on and I cannot seem to solve the import issues with the Folium library. Has anyone else solved this problem?After encountering an error…

How you enable CBC to return best solution when timelimit? (Pyomo)

I am trying to use CBC(v2.10.3) on Pyomo to solve for a integer linear problem.When executing the solver, I am currently setting a timelimit of 600s.opt = SolverFactory ("cbc")opt.options[sec…

SSL cert issue with Python Requests

Im making a request to a site which requires SSL cert to access. When I tried to access the URL, I get SSL Certificate errorimport requests proxies = {"https":"https://user:pwd@host:port…

MatplotLib get all annotation by axes

im doing a project with Python and Tkinter. I can plot an array of data and i also implemented a function to add annotation on plot when i click with the mouse, but now i need a list of all annotation…

Using Pandas to applymap with access to index/column?

Whats the most effective way to solve the following pandas problem? Heres a simplified example with some data in a data frame: import pandas as pd import numpy as np df = pd.DataFrame(np.random.randin…

Multiple URL segment in Flask and other Python frameowrks

Im building an application in both Bottle and Flask to see which I am more comfortable with as Django is too much batteries included.I have read through the routing documentation of both, which is very…

installing python modules that require gcc on shared hosting with no gcc or root access

Im using Hostgator shared as a production environment and I had a problem installing some python modules, after using:pip install MySQL-pythonpip install pillowresults in:unable to execute gcc: Permiss…

Using libclang to parse in C++ in Python

After some research and a few questions, I ended up exploring libclang library in order to parse C++ source files in Python.Given a C++ source int fac(int n) {return (n>1) ? n∗fac(n−1) : 1; }for …

Python one class per module and packages

Im trying to structure my app in Python. Coming back from C#/Java background, I like the approach of one class per file. Id like my project tree to look like this:[Service][Database]DbClass1.pyDbClass2…

PyMySQL Access Denied using password (no) but using password

Headscratcher here for me.I am attempting to connect to a database on my local MySQL 8.0.11.0 install from Python.Heres the code Im using :conn = pymysql.connect(host=localhost, port=3306, user=root, p…