本文實例講述了Python使用matplotlib模塊繪制圖像并設置標題與坐標軸等信息。分享給大家供大家參考,具體如下:
進行圖像繪制有時候需要設定坐標軸以及圖像標題等信息,示例代碼如下:
#-*- coding: utf-8 -*-#!/usr/bin/pythonimport matplotlib.pyplot as pltfrom numpy.random import randnx = range(100)y = randn(100)fig = plt.figure()ax = fig.add_subplot(1,1,1)ax.plot(x,y,'k--')ax.set_xticks([0,25,50,75,100])ax.set_xticklabels(['one','two','three','four','five'],rotation=45,fontsize= 'small')ax.set_title('m.survivalescaperooms.com - Demo Figure')ax.set_xlabel('Time')plt.show()運行結果如下:

總結如下:
① ax.set_xticks([0,25,50,75,100]) 實現設置坐標標記點;
② ax.set_xticklabels(['one','two','three','four','five'],rotation=45,fontsize= 'small') 在設置的標記點寫標記詞;其他的參數分別是設置字體的傾斜度以及字體的大小;
③ ax.set_title('Demo Figure')設置圖片的標題;
④ ax.set_xlabel('Time')設置橫軸的名稱。
希望本文所述對大家Python程序設計有所幫助。
新聞熱點
疑難解答