现象:

import pandas as pd
from numpy import *
import matplotlib.pyplot as plt
import matplotlib as mpl


ts = pd.Series(random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()
plt.show()

执行完毕(Process finished with exit code 0),但不显示图表。

但在jupter notebook中,可以正常显示图表

pyCharm pyplot.show()不显示图表的解决

在setting的interpretor中看到解释器为3.7

pyCharm pyplot.show()不显示图表的解决 为其添加matplotlib

pyCharm pyplot.show()不显示图表的解决(很奇怪,conda list显示没有该模块,但jupter能显示,pycharm中却没有matplotlib)

在源代码plot.show()后添加

print(mpl.get_backend())

执行,显示 “module://backend_interagg”

根据网上资料,修改上面的backend,即

import pandas as pd
from numpy import *
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('TkAgg')

ts = pd.Series(random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()
plt.show()
print(mpl.get_backend())

import matplotlib as mpl
mpl.use('TkAgg') (核心修改处)

则显示正常,如下:

pyCharm pyplot.show()不显示图表的解决

相关文章:

  • 2021-12-17
  • 2021-12-01
  • 2021-09-30
  • 2021-12-07
  • 2021-11-02
  • 2022-12-23
  • 2021-07-27
  • 2021-11-18
猜你喜欢
  • 2021-11-29
  • 2022-12-23
  • 2021-12-09
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案