Matplotlib图不共享y轴

时间:2019-09-01 14:26:01

标签: python matplotlib

我正在建立一个图表来比较几个神经网络的准确性。我将数据保存在一个csv中,但是当我创建绘图时,线条不共享y轴

image of the graph

y轴也乱了,并打印了准确的值

我人为地在两条线上都添加了0,0,这使它们共享单点,但否则它们不会重叠。

还请注意,x轴只有3个点,但这仅是显示行为的一个示例。


def find_max_reached(folder):
    result = 0
    for data in os.listdir(folder):
        with open(os.path.join(folder, data)) as csvfile:
            reader = csv.DictReader(csvfile)
            for row in reader:
                if int(row['examples']) > result:
                    result = int(row['examples'])
    return result

def accuracy_list(csvfile):
    accuracy = []
    reader = csv.DictReader(csvfile)
    for row in reader:
        accuracy.append(row['performance'])
    return accuracy

max_reached = find_max_reached(results_dir)

x = np.linspace(0, max_reached, num=3)

for data in os.listdir(results_dir):
    with open(os.path.join(results_dir, data)) as csvfile:
        plt.plot(x, accuracy_list(csvfile))

plt.show()
path = os.path.join(ROOT_DIR, "results", "graphs")
os.makedirs(os.path.dirname(path), exist_ok=True)
plt.savefig(os.path.join(path, "batch_accuracy_comp.png"))```

0 个答案:

没有答案