图未显示在blogdown帖子中:blogdown中pythonchunk中的plt.show()创建html图fi

2024-10-01 09:42:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个目录:

  1. 我的blogdown文件所在的位置,以及
  2. 其中我有数据文件和python-snipplet

为了执行使用数据文件的python-snipplet,我更改了blogdownPySnipplet.rmd文件中的目录。python-代码(以plt.show()结尾)执行得很好,但不是在我的blogdownPySnipplet.rmd派生的blogdownPySnipplet.html(在网站上)中显示绘图,而是在snipplet所在的目录中创建一个目录,并创建一个figure.html文件

执行.rmd之前的类似目录层次结构:

  -- blogdownDirectory
              -- blogdownPySnipplet.rmd
    -- otherDirectory
              -- python-snipplet
              -- dataFile1
              -- dataFile2
              ...

执行.rmd后的类似目录层次结构:

   -- blogdownDirectory
              -- blogdownPySnipplet.rmd
   -- otherDirectory
              -- python-sniplet
              -- dataFile1
              -- dataFile2
              ...
              -- blogdownPySnipplet
                       -- figure.html
                                 -- figureFile.html

如何让plt.show直接在网站上显示我的情节

```{r python}
knitr::opts_knit$set(root.dir = "C:/Users/shudras/Project2/experimental_data")
# to be able to load the data files into the pySnipplet
{python, python.reticulate = FALSE, 
code = readLines("C:/Users/shudras/Project2/experimental_data/pySnipplet.py")}
# executing the code and plotting the data files

# python code extract

import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable

# matplotlib import needs some extra attention
import matplotlib.pyplot as plt
import os 
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:\ProgramData\Anaconda3\Library\plugins\platforms'

files = os.listdir() # import data file names

# code where doing calculations and making subfigures...

plt.show()

Tags: 文件theimport目录dataos数据文件html