Skip to main content



# Packages
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

# Use LaTeX font
plt.rcParams.update({'text.usetex': True})

# Figure font config
label_font = {'fontfamily': 'Arial Black', 'fontsize': 12}
title_font = {'fontfamily': 'Arial Black', 'fontsize': 14}
text_font = {'family': 'Palatino Linotype', 'fontsize': 12}
legend_font = {'family': 'Palatino Linotype', 'size': 12}

# Generate data
item = [
    'Model 1',
    'Model 2',
    'Model 3',
    'Model 4',
    'Model 5',
]

value = np.array([
    [1, 1.5, 2, 2.5, 3], 
    [0.2, 0.4, 0.6, 0.8, 1], 
    [0.1, 0.1, 0.1, 0.1, 0.1] 
])

std = np.array([
    [0.1, 0.15, 0.2, 0.25, 0.3], 
    [0.05, 0.05, 0.05, 0.05, 0.05], 
    [0, 0, 0, 0, 0] 
])

# Plot
fig, ax = plt.subplots(1, figsize=(4, 4))

# Color list
color = [cm.Set2(1)] + [cm.Set2(0)] * 4

ax.bar(
    item, value[0], yerr=std[0], 
    width=0.65, 
    color=color, 
    capsize=2, 
)

# Label and title
ax.set_ylabel('Y Label', **label_font)
ax.set_title('Single Hist Plot (Vertical)', **title_font)

# Axis
ax.tick_params(axis='both', which='major', labelsize=12)

# Grid
ax.grid(axis='both', color='black', alpha=0.1)

plt.tight_layout()
plt.savefig('../fig/single-hist-vertical.jpg', dpi=300)