Search code examples
pythonmatplotlibtext

Dynamically Updating Text outside Matplotlib (Python)


Morning All,

I'm stuck with an issue in Matplotlib whereby I am unable to clear all features outside of the plots.

Context

I have two axes, ax1 is a scatterplot, while ax2 is a 3D Bar chart plot (fig. 1).

There is a function (drillhole_summary) that runs whenever a point (or drill hole) is selected in ax1. This drillhole_summary() then displays the names of all drill holes selected outside of both ax1 and ax2.


            def drillhole_summary():

                dh_textstr = ('Drill Holes Selected: ' + str(drillholes_selected))
                plt.gcf().text(0.10, 0.40, dh_textstr, fontsize=14)

The Issue

The issue is that previous instance of the names of drill holes isn't update, it is just being overwritten.

Figure 1 Figure 1 Click to enlarge

Attempted Solutions

I have attempted to write over the text with the same string but in a white coloured font. This creates a ghostly image of text. Other attempts result in both ax1 and ax2 getting wiped clean, or the programme becomes blank.

Any feedback will be appreciated!


Solution

  • The only solution that I could come up with was to make use the ax1 legend and dynamically update it with each click on ax1 (see image).

    enter image description here