6

Is it possible to get interactive plot when using jupyter in PyCharm IDE ? If not, Why ?

By interactive plot I mean a plot in a window where I can zoom.

I tried this, but python always crash :

#%%
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

mpl.use('TkAgg')  # or can use 'TkAgg', whatever you have/prefer 'Qt5Agg'


# Data for plotting
t = np.arange(0.0, 2.0, 0.00001)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',
       title='About as simple as it gets, folks')
ax.grid()

plt.show()

enter image description here

Thomas LESIEUR
  • 408
  • 4
  • 14
  • try pasting the `%matplotlib inline` command under your matplotlib import. – PreciXon Aug 30 '21 at 17:34
  • Hi, thanks for the advice but it did'nt change anything. Does it work for you ? – Thomas LESIEUR Aug 30 '21 at 17:41
  • 1
    I honestly haven't tried, and thought my suggestion migh help. I don't use pycharm when it comes to jupyter notebooks, and prefer VSCode. If you are willing to make the shift (which I HIGHLY recommend), VSCode can plot the figures right under the code blocks, identical to the original jupyter notebooks. Here's a picture to give you an idea. https://imgur.com/a/cm3ptpk – PreciXon Aug 30 '21 at 20:03
  • Thanks fo the preview ! Do you know if it's possible to zoom in thoses plot under the code blocks ? – Thomas LESIEUR Aug 30 '21 at 22:36
  • 1
    Oh you are in for an absolute TREAT. If you use the plotly library, you have options to zoom in and out, as well as others such as cropping the graph and examining only those areas you're interested in, all within the output frame. With matplotlib and seaborn however, VSCode gives you an option to "expand image" in the output frame, and by clicking it, it opens the image in a new tab (sort of like a new chrome tab), and you can do all the zooming and other good stuff there. Here are some examples: https://imgur.com/a/bMbZS3b. If you're making the shift, welcome to the VSCode Community! – PreciXon Aug 31 '21 at 02:52

1 Answers1

0

You can give a try to the "Let's-Plot in SciView" plugin for PyCharm. It doesn't provide zooming controls but you can achieve the effect by adjusting xlim/ylim options in coordinate system.

Plugin: https://plugins.jetbrains.com/plugin/14379-lets-plot-in-sciview

Docs: https://lets-plot.org/

alshan
  • 136
  • 3