[英]How to change the y tick label in matplotlib
下面的代碼生成一個散點圖 plot。
#KNNClassifier_weighted
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(100, 30))
xy = np.array([
(x, y) for x, lst in df_param.items()
for sublst in lst for y in sublst
])
plt.scatter(*xy.T, s=500, edgecolors='black', linewidth=3)
plt.title("KNNClassifier: weighted",fontsize=80)
# Setting the x and y labels
plt.xlabel("Iteration",fontsize=80)
plt.ylabel("value",fontsize=80)
#labels=["True", "False"]
# Setting the number of ticks
plt.xticks(np.arange(0, len(df_param)+1, 10),fontsize=34, rotation=90)
plt.yticks(fontsize=45)
plt.xlim(xmin=0)
plt.show()
{0: [[True], [False], [True], [False], [False], [False]], 1: [[False], [True], [False], [False], [False]], 2: [[False], [True], [False], [False]], 3: [[False], [False], [False]], 4: [[False], [False]], 5: [[False]], 6: [], 7: [], 8: [[False]], 9: [], 10: []}
當我嘗試將標簽放入數組並將其設置為 yticks 時。
labels=["True", "False"]
# Setting the number of ticks
plt.xticks(np.arange(0, len(df_param)+1, 10),fontsize=34, rotation=90)
plt.yticks(labels, fontsize=45)
我收到轉換錯誤。
ConversionError: Failed to convert value(s) to axis units: ['True', 'False']
我希望將 dataframe 中的值用作標簽。
我自己沒有嘗試過,但這樣的事情可能會有所幫助:
plt.yticks([1.0, 0.0], labels, fontsize=45)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.