-Code entlehnt matplotlib: colorbars and its text labelsWie kann ich die Schriftart von "cbar.ax.text" in Arial ändern?
ich auf eine ähnliche Figur arbeite, aber ich kann nicht herausfinden, wie die Schrift von „cbar.ax.text“ Arial zu ändern.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import ListedColormap
#discrete color scheme
cMap = ListedColormap(['white', 'green', 'blue','red'])
#data
np.random.seed(42)
data = np.random.rand(4, 4)
fig, ax = plt.subplots()
heatmap = ax.pcolor(data, cmap=cMap)
#legend
cbar = plt.colorbar(heatmap)
cbar.ax.get_yaxis().set_ticks([])
for j, lab in enumerate(['$0$','$1$','$2$','$>3$']):
cbar.ax.text(.5, (2 * j + 1)/8.0, lab, ha='center', va='center')
cbar.ax.get_yaxis().labelpad = 15
cbar.ax.set_ylabel('# of contacts', rotation=270)
# put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)
ax.invert_yaxis()
#lebels
column_labels = list('ABCD')
row_labels = list('WXYZ')
ax.set_xticklabels(column_labels, minor=False)
ax.set_yticklabels(row_labels, minor=False)
plt.show()
Mögliches Duplikat von [So ändern Sie die Schriftgröße auf einem Matplotlib-Plot] (https://stackoverflow.com/questions/3899980/how-to-change-the-font-size-on-a-matplotlib-plot) – Luce
@Luce Ich habe versucht, aber es ändert die Schriftart von allem außer den Etiketten der cbar. – user8087767