Skip to content
Advertisement

Matplotlib, what to plot in a loop with user input

this is the first time i ask a question in here, so i hope i can ask it correctly any feedback on clarity is also appriciated.

I am forced to use matplotlib’s plot function in the code i am currently writing, due to the datastructure i am working with. But it does not do well with plotting in loops. What i aim to do, with my plot, is to be able to modify a background window determined by the user, and either accept or reject the output. But as i understand there is some conflict between matplotlibs interactive function and the use of a loop. I am relativly new to python, so the code might not be the prittiest, but useually i gets the job done. I am however at a complete loss for the particular problem. I have seen similair problems on the internet, which have been solved with plt.pause(‘timeinterval’) but this is not an option in my case. or atleast i cannot see how i can use it, since i want to wait for user input. I have also tried plt.waitforbuttonpress() but this is not very intuetive, i cannot choose which button it should wait for.

I guess a third option is to extract the data from the format hyperspy uses and then make a canvas of my own, which forfills my needs, but this is very tidious for me, due to my lack of experience.

Do anyone have any alternative ways of producing a plot, preferably with matplotlib such that i can achive what i am trying?

By the way, i have also tried turning off interactive mode, and this does not do the trick unfurtunatly.

Some information about the specs: This is running on a windows pc, using jupyterlab and python 3.10

I hope my dilemma is clear.

JavaScript

Advertisement

Answer

JavaScript

Output:

enter image description here

After user input and clicking the button:

enter image description here

More user input:

enter image description here

Does it satisfy your need or am I getting further away from your initial question?

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