我试图复制以下情节从本文中:

图显示了五次运行的平均精度,垂直值显示了最小和最大精度。
我如何用特定的值来添加这些垂直散射点呢?
我现在的代码是:
def plot_losses(losses: Dict[float, Dict[float, List[float]]]) -> None:
    """
    Plot the evolution of the loss regarding the sparsity level and iteration step
    Args:
        losses (Dict[float, Dict[float, List[float]]]): Dict containing the losses regarding the sparsity level and iteration step
    """
    plt.clf()
    plt.figure(figsize=(20, 10))
    plt.tight_layout()
    sparsity_levels = [round(sparsity_level, 2) for sparsity_level in losses.keys()]
    for sparsity_level, key in zip(sparsity_levels, losses.keys()):
        plt.plot(list(losses[key].keys()), list(losses[key].values()), '+--', label=f"{100 - sparsity_level:.2f}%")
    plt.show()发布于 2022-10-21 09:48:59
更喜欢plt.errorbar (相对于plot_losses循环中的plt.plot ),并使用参数yerr添加具有min和max值的垂直条。
下面是一个示例:
import numpy as np 
import matplotlib.pyplot as plt 
# Generate  data
x = np.arange(10) + 1
y1 = x/20
y2 = x/25
# Generate data for pseudo-errorbars
y1_err = np.array([y1[0::2]/20, y1[1::2]/7]).reshape(1, 10)
y2_err = np.array([y2[0::2]/30, y1[1::2]/13]).reshape(1, 10)
# Plot data
plt.errorbar(x, y1, yerr=y1_err, label="100", capsize=3, capthick=3.5)
plt.errorbar(x, y2, yerr=y2_err, label="51.3", capsize=3, capthick=3.5)
plt.legend(bbox_to_anchor=(0.95, 1.1), ncol=3)
plt.show()这意味着:

https://stackoverflow.com/questions/74150240
复制相似问题