Comments (2)
This seems useful, but hard to generalize. I am skeptical that it would be made default part of Matplotlib proper. We have a pretty straightforward GUI event handler that would be just a few lines of code to make something like this work:
import matplotlib.pyplot as plt
import numpy as np
def on_click(event):
for i, ax in enumerate(axs.flat):
if event.inaxes == ax:
fig, new_ax = plt.subplots()
new_ax.imshow(images[i], cmap='gray')
new_ax.set_title(f'Image {i+1}')
new_ax.axis('off')
fig.show()
def create_random_image():
return np.random.rand(100, 100)
# Generate four random images
images = [create_random_image() for _ in range(4)]
# Create a main figure to display the images
main_fig, axs = plt.subplots(2, 2, layout='compressed')
for i, ax in enumerate(axs.flat):
ax.imshow(images[i], cmap='gray')
ax.set_title(f'Image {i+1}')
ax.axis('off')
# Connect the click event
main_fig.canvas.mpl_connect('button_press_event', on_click)
plt.show()
from matplotlib.
Similarly, you could change the position of clicked axes
import matplotlib.pyplot as plt
import numpy as np
cache = {}
def on_click(event):
ax = event.inaxes
if ax is None:
return
if ax not in cache:
cache[ax] = ax.get_subplotspec()
ax.set_position([0, 0, 1, 1])
ax.set_zorder(5)
else:
sp = cache.pop(ax)
ax.set_subplotspec(sp)
ax.set_zorder(1)
ax.set_in_layout(True)
print(ax.get_subplotspec())
ax.figure.canvas.draw_idle()
def create_random_image():
return np.random.rand(100, 100)
# Generate four random images
images = [create_random_image() for _ in range(4)]
# Create a main figure to display the images
main_fig, axs = plt.subplots(2, 2, layout='compressed')
for i, ax in enumerate(axs.flat):
ax.imshow(images[i], cmap='gray')
ax.set_title(f'Image {i+1}')
ax.axis('off')
# Connect the click event
main_fig.canvas.mpl_connect('button_press_event', on_click)
plt.show()
from matplotlib.
Related Issues (20)
- [Bug]: for Python 3.11.9 gor error ValueError: PyCapsule_New called with null pointer
- [Bug]: y_label in wrong place after clearing for twinx axes HOT 2
- [ENH]: Ability to add custom colours and colourmaps to matplotlibrc HOT 1
- [Bug]: plt.imshow displays a non-zero array as all zeros HOT 3
- Maximum Alpha for Scatter HOT 7
- [Doc]: Update License Text to standard SPDX license HOT 11
- problem with pip install under Python 3.13.0b1 on Win 11 [Bug]: HOT 10
- [ENH]: Natural 3D rotation with mouse HOT 1
- [Doc]: Missing comma HOT 1
- [Bug]: set linestyle='dashed' raise error with quiver and legend HOT 4
- [ENH] Support for Multi-Color Line Legends in Plots
- [Doc]: Inheritance Diagrams Not Respecting Dark Mode HOT 1
- [Bug]: orientation indication shows up late in mplot3d, and then lingers HOT 1
- [Bug]: setting patchA of Annotation.arrow_patch has no effect HOT 2
- [Bug]: matplotlib broke compatibility with get_cmap in new release (3.9) HOT 2
- [Bug]: Button causes window to hang HOT 7
- [ENH]: Qt Designer support. HOT 2
- Plot_surface add wrong value HOT 1
- [Bug]: show(block=False) freezes HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matplotlib.