NeuroKit icon indicating copy to clipboard operation
NeuroKit copied to clipboard

Show plots

Open VegardIversen opened this issue 2 years ago • 11 comments

Question and context Hi, Great library ! I have a question about this implementation.

ecg_signal = nk.data(dataset="ecg_3000hz")['ECG'] 
_, rpeaks = nk.ecg_peaks(ecg_signal, sampling_rate=3000) 
plot = nk.events_plot(rpeaks['ECG_R_Peaks'], ecg_signal)

This code will not show any plots, I can see why in the code, but is there a reason for why plt.show() is not called when show=True. For me it would be logical to actually see the plot when i call a plotting function with show=True as a parameter, and not just return a Axes object.

VegardIversen avatar Dec 03 '21 15:12 VegardIversen

Hi 👋 Thanks for reaching out and opening your first issue here! We'll try to come back to you as soon as possible. ❤️ kenobi

welcome[bot] avatar Dec 03 '21 15:12 welcome[bot]

Hi @VegardIversen, it should definitely return a plot as you said, since the default is show=True. Here we call the pandas plot() function instead rather than matplotlib plt.show(). Can I check with you what python IDE you are using?

zen-juen avatar Dec 04 '21 02:12 zen-juen

Hi @VegardIversen, it should definitely return a plot as you said, since the default is show=True. Here we call the pandas plot() function instead rather than matplotlib plt.show(). Can I check with you what python IDE you are using? @zen-juen I am using visual studio code. Im guessing the reason for it is that it seems to use jupyter notebook in the examples, and here you dont need to call the show function.

VegardIversen avatar Dec 04 '21 07:12 VegardIversen

Ah I think I misunderstood - I realize now that you're asking this more for conceptual understanding rather than asking for help to enable plotting!

Yes you're right about plt.show() being unnecessary when it comes to jupyer notebook or when using interactive mode (https://stackoverflow.com/questions/54422714/when-is-plt-show-required-to-show-a-plot-and-when-is-it-not) - I assume you're not running your code on VS code notebook/interactive mode? Are you running the code from the terminal?

zen-juen avatar Dec 04 '21 09:12 zen-juen

Yes im running the code from terminal. Was just a question about if it should be like that.

VegardIversen avatar Dec 04 '21 09:12 VegardIversen

Hmm I didn't think it would be a problem since we have return fig which should act similar to plt.show() (as with most of neurokit's plotting functions). Thoughts? @DominiqueMakowski

zen-juen avatar Dec 04 '21 10:12 zen-juen

My understanding of matplotlib's behaviour is too low to be of good advice here. I don't know what's the best practice...

From a design perspective, I think the goals would be, when running a function with show=True:

  • The plot shows up
  • Shows up only once (sometimes I've experienced the plot being duplicated)
  • The plot can be "recovered" outside the function for further customization/processing

I'm not sure what's the standard way to achieve that. In any case, we should at least be consistent and adopt the same approach in all our plotting

DominiqueMakowski avatar Dec 05 '21 01:12 DominiqueMakowski

I'm not sure what's the standard way to achieve that. In any case, we should at least be consistent and adopt the same approach in all our plotting

If I'm not wrong, we always initiate our matplotlib as fig and return fig at the end of the function (because sometimes we have internal functions that add more plotting features in between), which should make plt.show() not needed. But yeah good to double check

zen-juen avatar Dec 07 '21 03:12 zen-juen

return fig at the end of the function (because sometimes we have internal functions that add more plotting features in between)

The return fig is only used if the function only does plotting, but for functions that return something else then we don't return the fig so I'm not sure how it works

DominiqueMakowski avatar Dec 07 '21 03:12 DominiqueMakowski

I think it should be a plt.show() after initiating the plot. If you dont want unnecessary code when running it in jupyter you could make a check if its run in jupyter, or you can just include it either way because it will not affect jupyter (as far as i have found out).

VegardIversen avatar Dec 10 '21 09:12 VegardIversen

This issue has been automatically marked as inactive because it has not had recent activity. It will eventually be closed if no further activity occurs.

stale[bot] avatar Jun 10 '22 17:06 stale[bot]

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Sep 08 '22 17:09 stale[bot]