天天看點

matplotlib筆記01matplotlib元素

matplotlib元素

#正常導入方法
import matplotlib.pyplot as plt
           

1、分類(2大類)

(1)基礎類

line

marker點

text

lengend 圖例

grid 網格線

title

image

(2)容器類

figure 整個圖形

axes 坐标圖形(也就是figure的子圖)

axis 坐标軸(locator刻度位置,formatter顯示數值)

tick 刻度

層次: figure->axes->axis->tick

2、檢視對象

調整元素時候就要調用裡面的對象

1.檢視有哪些可用樣式

#檢視可用樣式
plt.style.available
           
matplotlib筆記01matplotlib元素

2.傳回目前目前狀态下的axes對象

matplotlib筆記01matplotlib元素
ax=plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# 設定上、右邊線不顯示
           

3.檢視目前axes對象下的元素

matplotlib筆記01matplotlib元素

4.傳回目前狀态下的figure、axes對象

plt.gcf()
plt._axes()
           
matplotlib筆記01matplotlib元素

3、調整元素

#圖表尺寸、分辨率
figure()  #figsize,dpi

#圖名,文字設定
title()  #str,fontdict文本格式

#x、y軸标題
xlabel()  #xlabel
ylbael()  #ylabel

#x、y軸範圍
axis()
xlim()  #xmin,xmax
ylim()  #ymin,ymax

#x、y軸刻度
xticks()  #ticks刻度數值,labels刻度名稱,fontdict
yticks()

#x、y軸主次網格線
grid()  #b有無網格,which主/次,axis,color,linestyle,linewidth,alpha透明度

#圖例設定
legend()  #loc,edgecolor,facecolor,fontsize