How to create a user created textbox on top of matplotlib figure?

404 views Asked by At

BackGround

I'm making this software right plot data as boxplots and scatter plots. To make the graph more informative and clear I wanted the user to be able to drag-create a textbox on top of the figure if they wanted to add notes. This way when people share the figure it can be explained through these notes.

Current Approach and Problem

I have used annotate function to create a textbox in the upper right corner of the screen to tell the user how many data points have been used, but there are of few problems with this approach.

This is the code I used to create a text box to tell the user how many data pts there are.

self.axes.text(.98, .98, 'Number of Data Points: {}'.format(len(self.cleanedY)),
                   verticalalignment='top', horizontalalignment='right',
                    transform=self.axes.transAxes,
                   color='black', fontsize=9.5)
  1. Extensive input that would have to be asked of the user. This includes the position coordinates, the actual text box, type of alignment.
  2. The only way I know how to collect this info would be to create a Qdialog window prompting for all these inputs, which would be too cumbersome.
  3. User doesn't have much control over being able to freely position the textbox and would have to know exact decimals to position the text box on the figure.

This is incredibly inefficient and inflexible. I want a way for the user to EASILY create these notes on the plot figure.

TLDR: Is there any way to develop a simple drag and create textbox option on a plot figure?

1

There are 1 answers

1
NoviceCoder On BEST ANSWER

I'm not sure if this is what your looking for, but i found this similar example online. It doesn't allow for user to create a textbox, but adds annotations to the figure and allows you to move them around.

here's the link

http://scipy-cookbook.readthedocs.io/items/Matplotlib_Drag_n_Drop_Text_Example.html