I want to edit the values and sizes of the numbers and labels in the saved graph

Viewed 45

I want to edit the values and sizes of the numbers and labels in the saved graph!

I have created a graph with code like this: I want to be able to edit the values in the graph when I save this graph and use it in ppt, word, etc. I tried saving it in the svg file format, but the svg format seemed to be saving each number as an image. Is there a better way?

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

data = np.array([[0.891, 0.111, 0.000, 0.000, 0.000],
              [0.027, 0.971, 0.001, 0.000, 0.000],
              [0.000, 0.001, 0.997, 0.001, 0.001],
              [0.000, 0.000, 0.001, 0.997, 0.002],
              [0.000, 0.001, 0.005, 0.028, 0.966]])
axis_labels = np.array(["lable_1", "lable_2", "lable_3", "lable_4", "lable_5"])

fig, ax = plt.subplots(figsize=(8,8))
im = ax.imshow(data, cmap='Blues')
ax.set_xticks(np.arange(len(axis_labels)))
ax.set_yticks(np.arange(len(axis_labels)))
ax.set_xticklabels(axis_labels)
ax.set_yticklabels(axis_labels, rotation=90, ha='center', va='center')

for i in range(len(axis_labels)):
    for j in range(len(axis_labels)):
        if i==j:
            text = ax.text(j, i, data[i, j], ha='center', va='center', color='w')
        else:
            text = ax.text(j, i, data[i, j], ha='center', va='center')

ax.set_title('title', fontsize=16)
ax.set_xlabel('x_label', fontsize=14)
ax.set_ylabel('y_label', fontsize=14)
plt.colorbar(im)
plt.show()
0 Answers
Related