Bookdown pdf 中的 Python 代码和输出不是多行

问题描述 投票:0回答:0

我正在尝试在

rmarkdown
中使用
bookdown
编写python代码。 python代码没问题。问题是当生成 pdf 书时,一些长的 python 代码和有时一些 python 代码的输出在 pdf 页面之外,因此它们不可见。请看下面的图片。

在图像中您可以看到

print ('The total number of rows and columns in the dataset is {} and {} respectively.'.format(iris_df.shape[0],iris_df.shape[1]))
功能代码不完全可见,但输出是可见的。另一种情况,对于
new_col = iris_df.columns.str.replace('\(.*\)','').str.strip().str.upper().str.replace(' ','_')
代码,整行代码是不可见的,也是代码的输出。同样的问题出现在
sns.scatterplot ()
代码行中。

我只是想知道

bookdown
pdf中是否有,代码和相关联的代码都不会在pdf页面之外。

注意:我尝试在

rmarkdown
中多行编写python代码,但没有成功,大多数情况下在
rmarkdown
中多行编写python代码时代码不执行。

  • pdfoutput1

这是我用来生成图像输出的代码 -

from sklearn import datasets
iris = datasets.load_iris()
iris.keys()
iris_df = pd.DataFrame (data = iris.data, columns = iris.feature_names)
iris_df['target'] = iris.target

iris_df.sample(frac = 0.05)
iris_df.shape
print ('The total number of rows and columns in the dataset is {} and {} respectively.'.format(iris_df.shape[0],iris_df.shape[1]))
iris_df.info()

new_col = iris_df.columns.str.replace('\(.*\)','').str.strip().str.upper().str.replace(' ','_')
          
new_col
iris_df.columns = new_col
iris_df.info()

sns.scatterplot(data = iris_df, x = 'SEPAL_LENGTH', y = 'SEPAL_WIDTH', hue = 'TARGET', palette = 'Set2')
plt.xlabel('Sepal Length'),
plt.ylabel('Sepal Width')
plt.title('Scatterplot of Sepal Length and Width for the Target Variable')
plt.show()
python r-markdown bookdown
© www.soinside.com 2019 - 2024. All rights reserved.