22 python數(shù)據(jù)可視化(精講坐標軸)

00 載入擴展庫

import numpy as np
import matplotlib.pyplot as plt

01 設置坐標軸位置

x=np.arange(3)
y=[0,1,0]

plt.axes([0.1,0.7,0.3,0.3],frameon=True,facecolor='y',aspect='equal')
plt.plot(x,y,color='b',ls='--')
plt.axes([0.4,0.4,0.3,0.3],frameon=False,facecolor='y',aspect='equal')
plt.plot(x,y,color='b',ls='--')
plt.axes([0.7,0.1,0.3,0.3],frameon=True,facecolor='g',aspect='auto')
plt.plot(x,y,color='r',ls='--')
22 python數(shù)據(jù)可視化(精講坐標軸)的圖1

02 隱藏坐標軸

plt.axes([0.1,0.6,0.3,0.3],frameon=True,facecolor='y',aspect='equal')
plt.plot(x,y,color='b',ls='--')
plt.axes([0.7,0.2,0.3,0.3],frameon=True,facecolor='y',aspect='auto')
plt.plot(x,y,color='b',ls='--')
plt.axis('off')

22 python數(shù)據(jù)可視化(精講坐標軸)的圖2

03 控制刻度線和刻度標簽的顯示 plt.setp()

x=np.arange(3)
y=[0,1,0]
ax1=plt.subplot(211)
ax1.plot(x,y)
ax2=plt.subplot(212)
plt.setp(ax2.get_xticklabels(),visible=False)
plt.setp(ax2.get_yticklines(),visible=False)
ax2.plot(x,y)

22 python數(shù)據(jù)可視化(精講坐標軸)的圖3

04 控制坐標軸的顯示

x=np.linspace(1,5,20)
y=np.random.randint(1,10,20)
ax1=plt.subplot(211)
ax1.spines['top'].set_color('none')
ax1.plot(x,y)
ax2=plt.subplot(212)
ax2.spines['right'].set_color('none')
ax2.plot(x,y)
22 python數(shù)據(jù)可視化(精講坐標軸)的圖4

x=np.linspace(1,5,20)
y=np.random.randint(1,10,20)
ax1=plt.subplot(111)
ax1.spines['top'].set_color('none')
ax1.spines['right'].set_color('none')
ax1.spines['left'].set_position(('data',2))
ax1.spines['bottom'].set_position(('data',4))
ax1.plot(x,y)

22 python數(shù)據(jù)可視化(精講坐標軸)的圖5

05 plt.setp()在stem圖中的使用

x=np.linspace(1,5,20)
y=np.random.randint(1,10,20)
markerfmt,linefmt,basefmt=plt.stem(x,y)
plt.setp(markerfmt,marker='s',mfc='r',mec='k',ms=10)
plt.setp(linefmt,color='b',linestyle='-.')

22 python數(shù)據(jù)可視化(精講坐標軸)的圖6

06 ax.set_ 的用法

x=np.arange(3)
y=[0,1,0]
ax=plt.subplot(111)
ax.plot(x,y)
ax.set_xlim(0,5)
ax.set_ylim(0,3)
ax.set_xlabel('xx',color='r',size='large')
ax.set_ylabel('yy',color='g',size='small')
ax.set_title('zz',color='b',size='xx-large',loc='left')

22 python數(shù)據(jù)可視化(精講坐標軸)的圖7

ax.plot(x,y)
ax.set_xticks(range(0,3,0.5))
ax.set_yticks(range(0,2,0.4))

22 python數(shù)據(jù)可視化(精講坐標軸)的圖8


登錄后免費查看全文
立即登錄
App下載
技術鄰APP
工程師必備
  • 項目客服
  • 培訓客服
  • 平臺客服

TOP