組織モードでレポートを作成しようとしています。csv ファイル (1 列 3 行、浮動小数点数) からデータを読み取り、棒グラフで比較し、グラフをレポートに埋め込んで、latex にエクスポートしてから pdf にエクスポートできるようにします。
R_plot が正常に動作するため、Python コードのバー作成部分で行っていることのように理解するのが困難です。つまり、チャートは同じ org-mode :export :results :file 設定でレポートに埋め込まれます。
Pythonコードで何が間違っていますか? インタラクティブ モードで Python コードを実行すると、チャートは問題なく生成されますが、セル ブロックで実行すると、何らかの理由で py_comparison.png が保存されません。
#+NAME: R_plot
#+BEGIN_SRC R :exports both :results output graphics :file r_comparison.png
# graph in R
library("ggplot2")
performance <- read.csv("comparison.csv", header=FALSE)$V1
df <- data.frame(resource = c("1node1core", "1node8core", "2node8core"), performance = performance)
p <- ggplot(data = df, aes(x=resource, y=performance)) +
geom_bar(stat="identity", fill="steelblue") +
theme_minimal() +
ggtitle("Computation time (min) vs. Resource (type)")
p
#+END_SRC
#+NAME: python_plot
#+BEGIN_SRC python :exports both :results output graphics :file py_comparison.png
import matplotlib.pyplot as plt; plt.rcdefaults()
import matplotlib.pyplot as plt
import csv
objects = ['1node1core', '1node8core', '2node8core']
y_pos = list(range(0, len(objects)))
performance = []
with open('comparison.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
for row in reader:
f_row = float(row[0])
performance.append(f_row)
plt.bar(y_pos, performance, align='center', alpha=0.5)
plt.xticks(y_pos, objects)
plt.ylabel('Time')
plt.title('Resource vs. Time')
plt.show()
#+END_SRC