我正在尝试通过 RStudio 绘制 seaborn 热图。
我在 R 中使用reticulate
包。
下面是我的代码:
library(reticulate)
use_condaenv("python36", conda = "auto", required = FALSE)
os <- import("os")
os$listdir(".")
py_available()
sns <- import('seaborn')
plt <- import('matplotlib.pyplot')
pd <- import('pandas')
dat <- AirPassengers
# convert time series to data frame
dat <- data.frame(matrix(dat, ncol=frequency(dat), dimnames=dimnames(.preformat.ts(dat)) ))
dat
sns$heatmap(r_to_py(dat), fmt = "g", cmap = "viridis")
plt$show()
但是,我收到以下错误,并且我的 R session 在到达 seaborn 热图线时被中止。我应该怎么做才能修复此错误?
最佳答案
我在安装 PyTorch 和 matplotlib
的 RStudio daily build 1.2.114 和 Anaconda Python 3.7 环境中遇到了同样的问题。
我按照@Sheperd 的说明进行了以下更改,指向安装了 matplotlib
的环境;在我的例子中 pytorch37
:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import os
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/Users/user_name/Anaconda3/envs/pytorch37/Library/plugins/platforms'
t = np.arange(0.0, 2.0, 0.01)
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()
现在,找到了 PyQt
并且 RStudio 不再崩溃。
关于python - Qt平台插件问题Rstudio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50085788/