[英]How to change the color of one datapoint of line graph
我正在嘗試 plot 下圖中缺少的一些數據點。 對於第二個柱,最后一個數據點,沒有任何數據點。 我需要這個丟失的數據點以紅色表示,並且不希望 go 的線為 0。非常感謝任何幫助
plt.figure(figsize=(3,2))
no = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
point_1 = [86.317,86.317, 86.3175, 86.317, 86.317, 86.317,86.317, 86.317,86.317, 86.317]
point_1 = [88.404, 88.404,88.404, 88.404, 88.404, 88.404, 88.404,88.404, 88.404, 88.404]
point_2 = [76.3671,85.0843,80.4446,83.8689,83.868,79.4610,83.6540,78.4579,82.666,0]
point_2 = [72.501, 81.245,76.507,80.989,81.191,77.570,81.817,78.354,82.230,0]
plt.plot(no, point_1, color='orange', marker='^', linestyle='dashed',label='Measured 1 ')
plt.plot(no, point_1, color='orange', marker='*', linestyle='dashed',label='Predicted 1')
plt.plot(no, point_2, color='grey', marker='^', linestyle='dashed',label='Measured 2')
plt.plot(no, point_2, color='grey', marker='*',linestyle='dashed',label='Predicted 2')
plt.ylim(0, 100)
plt.xticks(no,fontsize='8')
#str_x=[l for l in no if not l in measured_3]
#for s_x in str_x:#
# plt.text(s_x,62,'*', color='r')
#plt.legend(loc='upper right',prop={'size': 3.5})
plt.xlabel('no.')
plt.ylabel('Ms')
如您所示使用紅線和紅點是不好的做法。 我會非常清楚並使用紅色問號。
你所要做的就是
numpy.nan
替換零,使其被忽略。import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(3,2))
no = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
point_1 = [86.317,86.317, 86.3175, 86.317, 86.317, 86.317,86.317, 86.317,86.317, 86.317]
point_1 = [88.404, 88.404,88.404, 88.404, 88.404, 88.404, 88.404,88.404, 88.404, 88.404]
point_2 = [76.3671,85.0843,80.4446,83.8689,83.868,79.4610,83.6540,78.4579,82.666,0]
point_2 = [72.501, 81.245,76.507,80.989,81.191,77.570,81.817,78.354,82.230,np.nan]
plt.plot(no, point_1, color='orange', marker='^', linestyle='dashed',label='Measured 1 ')
plt.plot(no, point_1, color='orange', marker='*', linestyle='dashed',label='Predicted 1')
plt.plot(no, point_2, color='grey', marker='^', linestyle='dashed',label='Measured 2')
plt.plot(no, point_2, color='grey', marker='*',linestyle='dashed',label='Predicted 2')
plt.ylim(0, 100)
plt.xticks(no,fontsize='8')
#str_x=[l for l in no if not l in measured_3]
#for s_x in str_x:#
# plt.text(s_x,62,'*', color='r')
#plt.legend(loc='upper right',prop={'size': 3.5})
plt.xlabel('no.')
plt.ylabel('Ms')
plt.text(10, 82.230, "?", color="red", ha="center", va="center")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.