我正在嘗試為圖中缺少的一些資料點繪制下圖。對于第二個條形,最后一個資料點沒有任何資料點。我需要這個缺失的資料點用紅色表示,不希望這條線變成 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')

uj5u.com熱心網友回復:
按照您的指示使用紅線和紅點是不好的做法。我會非常清楚并使用紅色問號。
你所要做的就是
- 將零替換為
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")
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/367141.html
上一篇:更新資料庫中的列時出錯-違反完整性約束:列'xxxxxxxx'不能為空
下一篇:修復圖中軸值的范圍
