Skip to content
Advertisement

Dynamic subplot using Figures in Matplotlib

I want to create a subplot using matplotlib with pysimplegui where each time i select some signals-checkbox(list of values) i should get a plot corresponding to it which will dynamically increase or decrease in size based on my selection so when i select a checkbox the respective plot will be plotted and eqaully spaced and when i deselect a plot it should be gone and other plots should automatically occupy the space Programming Language – Python3 Matplotlib – 3.6.2

My Requirement:

  1. There will always be maximum 10 rows and 1 column in my subplot (matplotlib)
  2. So lets say iam making a call to “plt.show()” after making 1 plot my result should have only one plot at that moment occupying the whole figure
  3. Now iam adding one more plot and then calling “plt.show()”, now it should have 2 plots occupying the fig equally this would be the same for 3,4,5 … 10 plots but all these plots should have a single shared axis whichever is at the bottom
  4. And also a way to delete a plot at any instance of time so for instance i make a plot say axis1 and then I make a plot axis2 now I want axis1 to be deleted after which only my axis2 plot will be there occupying the whole figure

The below code satisfies most of my requirement but its just that the axis are not shared with each other and also the sizing of each plots are different

reff1: Changing matplotlib subplot size/position after axes creation reff2: Dynamically add/create subplots in matplotlib

JavaScript

Advertisement

Answer

Here is a basis for the interactive part.

I remove all axes from the figure at each new selection and add the newly selected ones on a relevant GridSpec.

Still axes are not redrawn every time thanks to @lru_cache.

Edit: Added shared x axes

JavaScript

dynamic plots

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement