在 Ubuntu 中顯示 Matplotlib 圖形(和其他 GUI)
使用 matplotlib 的繪圖方法並使用不同的顏色設定圖例。
步驟
使用 plt.xlabel() 方法設定 X 軸標籤。
使用 plt.ylabel() 方法設定 Y 軸標籤。
使用 [9, 5]、[2, 5] 和 [4, 7, 8] 陣列,使用 plt.plot() 方法繪製線條。
初始化兩個變數;location = 0 表示最佳位置,border_drawn_flag = True(True,如果要為圖例繪製邊框。False,如果不繪製邊框)。
對圖例使用 plt.legend() 方法,並相應設定 location 和 border_drawn_flag,以在圖表中獲得完美的圖例。
使用 plt.show() 方法顯示圖形。
示例
import matplotlib.pyplot as plt
plt.ylabel("Y-axis ")
plt.xlabel("X-axis ")
plt.plot([9, 5], [2, 5], [4, 7, 8])
location = 0 # For the best location
legend_drawn_flag = True
plt.legend(["blue", "orange"], loc=0, frameon=legend_drawn_flag)
plt.show()輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP