Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [matplotlib]Multiple persistent modifiable rectangle selector
#1
Hi,

I am currently trying to display an image with several highlighted and modifiable region of interests. I want to solve it by using for example the rectangleselector from the matplotlib.widgets.
The issue is just I am not able to blend in multiple persistent dragable resizeable bounding boxes.
The example is here.
https://matplotlib.org/3.1.0/gallery/wid...ector.html Wrote:
from matplotlib.widgets import RectangleSelector
import numpy as np
import matplotlib.pyplot as plt


def line_select_callback(eclick, erelease):
    'eclick and erelease are the press and release events'
    x1, y1 = eclick.xdata, eclick.ydata
    x2, y2 = erelease.xdata, erelease.ydata
    print("(%3.2f, %3.2f) --> (%3.2f, %3.2f)" % (x1, y1, x2, y2))
    print(" The button you used were: %s %s" % (eclick.button, erelease.button))


def toggle_selector(event):
    print(' Key pressed.')
    if event.key in ['Q', 'q'] and toggle_selector.RS.active:
        print(' RectangleSelector deactivated.')
        toggle_selector.RS.set_active(False)
    if event.key in ['A', 'a'] and not toggle_selector.RS.active:
        print(' RectangleSelector activated.')
        toggle_selector.RS.set_active(True)


fig, current_ax = plt.subplots()                 # make a new plotting range
N = 100000                                       # If N is large one can see
x = np.linspace(0.0, 10.0, N)                    # improvement by use blitting!

plt.plot(x, +np.sin(.2*np.pi*x), lw=3.5, c='b', alpha=.7)  # plot something
plt.plot(x, +np.cos(.2*np.pi*x), lw=3.5, c='r', alpha=.5)
plt.plot(x, -np.sin(.2*np.pi*x), lw=3.5, c='g', alpha=.3)

print("\n      click  -->  release")

# drawtype is 'box' or 'line' or 'none'
toggle_selector.RS = RectangleSelector(current_ax, line_select_callback,
                                       drawtype='box', useblit=True,
                                       button=[1, 3],  # don't use middle button
                                       minspanx=5, minspany=5,
                                       spancoords='pixels',
                                       interactive=True)
plt.connect('key_press_event', toggle_selector)
plt.show()

If you have an alternative approach please let me know.
I would like to have like in the aforementioned example multiple rectangle selector objects. I hope you can help me.

[Context: I would show a photo of a traffic scene, and I would let the programm create after a 2D object detection several bounding boxes. I would like to give the user the possibility to modify the position and size. The issue is: I can just make only one interactive persistent rectangles. I do not know how to append it, to have several interactive concurrent interactive rectangulars.]
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Spacing pie chart colours evenly in matplotlib? Giovanni_diJacopo 1 118 Jul-12-2019, 12:31 PM
Last Post: scidam
  Are all points within a rectangle? aapurdel 1 586 May-26-2019, 03:21 PM
Last Post: ichabod801
  Keras + Matplotlib causing crash spearced 2 324 May-17-2019, 09:47 AM
Last Post: spearced
  MatPlotLib 2d plot of current density? ruben 0 142 May-13-2019, 06:47 AM
Last Post: ruben
  How to arrange the four pictures of a matplotlib.pyplot? vokoyo 0 275 Apr-04-2019, 10:58 PM
Last Post: vokoyo
  Numpy and matplotlib in incorporated Python. CSKir 7 974 Jan-15-2019, 10:44 AM
Last Post: CSKir
  Oct2py and Matplotlib installation problems Leloup 2 467 Nov-23-2018, 03:32 PM
Last Post: Leloup
  how can I create a recursive graphic with matplotlib royer14 3 517 Nov-22-2018, 05:00 PM
Last Post: Gribouillis
  how can I create graphics using matplotlib royer14 8 677 Nov-21-2018, 07:02 AM
Last Post: Gribouillis
  double pendulum help. (matplotlib) FramedLink 1 492 Nov-08-2018, 11:46 AM
Last Post: FramedLink

Forum Jump:


Users browsing this thread: 1 Guest(s)