1、坐標軸范圍、名稱、刻度
ax.xlim():設置x坐標軸范圍
ax.ylim():設置y坐標軸范圍
ax.xlabel():設置x坐標軸名稱
ax.ylabel():設置y坐標軸名稱
ax.xticks():設置x軸刻度
ax.yticks():設置y軸刻度
#設置y軸
ax.set_ylim(0,10000)
#設置x軸:set_xlim 設置坐標軸的顯示范圍,范圍要能大到足夠包含所有值
ax.set_xlim(0,10)
2、坐標軸設置
gca():獲取當前坐標軸信息
ax.spines:設置邊框
ax.set_color:設置邊框顏色:默認白色
ax.spines:設置邊框
ax…xaxis.set_ticks_position:設置x坐標刻度數(shù)字或名稱的位置
ax…yaxis.set_ticks_position:設置y坐標刻度數(shù)字或名稱的位置
ax…set_position:設置邊框位置
3、旋轉(zhuǎn)坐標軸標簽
ax.autofmt_xdate(self, bottom=0.2, rotation=30, ha=’right’, which=None)
參數(shù):
bottom:此參數(shù)是subplots_adjust()子圖的底部。
rotation:此參數(shù)是xtick標簽的旋轉(zhuǎn)。
ha:此參數(shù)是xticklabels的水平對齊方式。
which:此參數(shù)選擇要旋轉(zhuǎn)的刻度標簽。
返回值:此方法不返回任何值。
雙軸設置
import matplotlib.pyplot as plt
import numpy as np
#創(chuàng)建圖形對象
fig = plt.figure()
#添加子圖區(qū)域
a1 = fig.add_axes([0,0,1,1])
#準備數(shù)據(jù)
x = np.arange(1,11)
#繪制指數(shù)函數(shù)
a1.plot(x,np.exp(x))
a1.set_ylabel('exp')
#添加雙軸
a2 = a1.twinx()
#‘ro’表示紅色圓點
a2.plot(x, np.log(x),'ro-')
#繪制對數(shù)函數(shù)
a2.set_ylabel('log')
#繪制圖例
fig.legend(labels = ('exp','log'),loc='upper left')
plt.show()
注意,版本不同可能導致代碼跑不通
文章來源:http://www.zghlxwxcb.cn/news/detail-709512.html
參考文檔:
Matplotlib:設置坐標軸范圍,刻度,位置,自定義刻度名稱,添加數(shù)據(jù)標簽
Matplotlib坐標軸格式文章來源地址http://www.zghlxwxcb.cn/news/detail-709512.html
到了這里,關于python matplotlib筆記:坐標軸設置的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!