いい感じのグラフの色を提案して。
- User
いい感じのグラフの色を提案して。
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
いい感じのグラフの色を提案して。
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
より魅力的なグラフの色を取り入れたコードを提案します:
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import beta
import matplotlib.cm as cm
def plot_beta_bars(data, save_path):
"""
data: [
{
'label': '項目1',
'alpha': 10,
'beta': 2
},
...
]
"""
# 日本語フォントの設定
plt.rcParams['font.family'] = 'MS Gothic' # Windows用
# plt.rcParams['font.family'] = 'IPAGothic' # Linux/Mac用
# データ準備
n_items = len(data)
labels = [item['label'] for item in data]
means = [item['alpha'] / (item['alpha'] + item['beta']) for item in data]
stds = [np.sqrt((item['alpha'] * item['beta']) /
((item['alpha'] + item['beta'])**2 * (item['alpha'] + item['beta'] + 1)))
for item in data]
# カラーパレットの設定(ビビッドなブルーからティールのグラデーション)
colors = plt.cm.viridis(np.linspace(0.1, 0.8, n_items))
# プロット
fig, ax = plt.subplots(figsize=(10, 6))
fig.set_facecolor('#f8f9fa') # 背景色を軽いグレーに
ax.set_facecolor('#f8f9fa')
# 棒グラフの位置
x = np.arange(n_items)
# 棒グラフ(幅を最大に)
bars = ax.bar(x, means, width=0.8, yerr=stds, capsize=5,
color=colors, edgecolor='black', linewidth=0.5,
error_kw={'ecolor': '#555555', 'capthick': 1.5})
# ラベル設定
ax.set_xticks(x)
ax.set_xticklabels(labels, fontsize=11)
# 期待値を表示(エラーバーとの重なりを避けるため、上方にオフセット)
for i, bar in enumerate(bars):
height = bar.get_height()
offset = stds[i] + 0.02 # エラーバーの上に適度な余白を設定
ax.text(bar.get_x() + bar.get_width()/2., height + offset,
f'{means[i]:.3f}',
ha='center', va='bottom', fontsize=10, fontweight='bold')
# グラフの体裁調整
plt.title('ベータ分布のパラメータ', fontsize=14, pad=15)
plt.ylabel('期待値', fontsize=12)
# Y軸の範囲を自動調整(数値表示が見切れないように)
ymax = max([mean + std + 0.1 for mean, std in zip(means, stds)])
plt.ylim(0, ymax)
# グリッド線を追加(薄い色で)
ax.grid(axis='y', linestyle='--', alpha=0.3)
# 枠線を薄く
for spine in ax.spines.values():
spine.set_color('#cccccc')
# 保存
plt.tight_layout()
plt.savefig(save_path, dpi=300)
plt.close()
# 使用例
data = [
{'label': '項目1', 'alpha': 10, 'beta': 2},
{'label': '項目2', 'alpha': 5, 'beta': 5},
{'label': '項目3', 'alpha': 2, 'beta': 10}
]
plot_beta_bars(data, 'beta_bars.png')
主な色の改善点:
その他の改善点:
別のカラーパレットを試したい場合は、以下のいずれかに変更できます:
plt.cm.plasma: 紫から黄色のグラデーションplt.cm.cool: シアンからマゼンタのグラデーションplt.cm.autumn: 赤から黄色のグラデーションplt.cm.tab10: 異なる色相の10色パレット