Spaces:
Sleeping
Sleeping
File size: 2,025 Bytes
04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 04eb3e6 53823af 11b7d82 53823af 11b7d82 53823af 04eb3e6 bdccaea 53823af bdccaea 11b7d82 53823af |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import os
import tempfile
import shutil
import gradio as gr
import matplotlib.cm as cm
import pandas as pd
import japanize_matplotlib
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def all_likelihood_plot(csv_file_name, tmpdir):
df = pd.read_csv(csv_file_name, header=[1, 2])
df = df.drop(df.columns[[0]], axis=1)
columns = df.columns.droplevel(1)
# 重複を削除
columns = columns.drop_duplicates()
likelihood = [df[x]["likelihood"] for x in columns]
a = pd.DataFrame(likelihood, index=columns).T
#平均値を求める
point_average = a.mean()
parts = ["指節1", "指節2", "指節3", "指節4", "指節5", "指節6", "指節7", "指節8", "指節9",
"指節10", "指節11", "指節12", "指節13", "指節14", "触角(左)", "触角(右)", "頭部", "腹尾節"]
# カラーマップの設定
a.columns = parts
cmap = plt.get_cmap('rainbow')
# バイオリン図のプロット
sns.set(style="whitegrid",font="IPAexGothic")
fig, ax = plt.subplots()
# データをバイオリンプロットで描画
sns.violinplot(data=a, palette=[cmap(i)
for i in np.linspace(0, 1, len(columns))], ax=ax,inner=None)
# 横軸のラベルを重ならないように
plt.xticks(rotation=65)
ax.set_title('付属肢別の尤度')
ax.set_xlabel('付属肢')
ax.set_ylabel('尤度')
#それぞれの要素の平均値をプロット
plt.scatter(x=parts, y=point_average, color='black', marker='x')
# 最大値を1に
plt.ylim(0, 1)
# fig.set_figwidth(10)
#ラベルがはみ出ないように
plt.tight_layout()
# グラフを表示
plt.savefig(f"likelihood.png", dpi=300)
def main(csv_file):
with tempfile.TemporaryDirectory(dir=".") as tmpdir:
all_likelihood_plot(csv_file, tmpdir)
return f"likelihood.png"
iface = gr.Interface(fn=main, inputs="file",
outputs="image", title="尤度のグラフを作成します。")
iface.launch()
|