使用jupyter pycharm时如何获得pyplot的交互式绘图

Tho*_*EUR 6 python matplotlib pycharm lets-plot

在 PyCharm IDE 中使用 jupyter 时是否可以获得交互式绘图?如果不是,为什么?

我所说的交互式绘图是指窗口中可以缩放的绘图。

我尝试过这个,但 python 总是崩溃:

#%%
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()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

小智 0

您可以尝试一下 PyCharm 的“Let's-Plot in SciView”插件。它不提供缩放控件,但您可以通过调整坐标系中的xlim/选项来实现效果。ylim

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

文档: https: //lets-plot.org/