我有一個主要問題,我似乎無法找到任何解決方案。 基本上,我繪製了2D字段與來自matplotlib工具的pcolormesh。python matplotlib當X和Y是矩陣時X勾選位置
現在,如果我想繪製2D場,X和Y是我的X和Y尺寸,而C是我想用pcolormesh繪製的矩陣,我所要做的就是:(請注意,下面的代碼是我的實際代碼大大簡化)
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.cm import get_cmap
number_of_ticks=10 # Insert number of ticks wanted
#'Insert here a non pertinent section of 1000 lines of code where I Acess the data to my '
#'variable C and my dimensions X and Y,
#'All we need to know is that X and Y are arrays, and C is a Matrix'
fig,ax = plt.subplots(1,1,figsize=(15,12),squeeze= False)
given_positions=np.linspace(min(X),max(X),number_of_ticks)
# Un necessary section here where I create a new array 'axticklatlonname',
#wich are the names for the 10 ticks that I created earlier with given_positions
new_tick_location=given_positions
ax.set_xticks(new_tick_locations)
ax.set_xticklabels(axticklatlonname)
mycmap=get_cmap('Jet')
mycmap.set_over('b')
col=ax.pcolormesh(X,Y,C,norm=LogNorm(vmin=-60,vmax=10),cmap=mycmap,shading='flat')
cbar=fig.colorbar(col,ax=ax)
cbar.ax.set_ylabel('TT')
cbar_ax=fig.add_axes
直到現在,它的工作原理,它產生了我想要的結果。
我的問題是,我的維Y實際上也是一個變量;我的身高取決於我在X軸上的位置。
這意味着該圖將改變,因爲C矩陣中的Y位置對於每個X位置不再是恆定的。
我解決了這個問題,通過將我的Y數組更改爲矩陣,並通過將我的X數組更改爲具有Y等價X數組的矩陣;現在
Xmatrix=np.tile(X(len(Y),1))
我可以積pcolormesh:
col=ax.pcolormesh(Xmatrix,Ymatrix,C,norm=LogNorm(vmin=-60,vmax=10),cmap=mycmap,shading='flat')
現在的問題是,我不能指定我的X刻度位置。
我試圖做獲取默認的X刻度位置值: ax.get_position()
而且我得到了作爲輸出B-盒([0.125,0.244],[0.9,0.324])) 這不告訴我我該如何指定我的Xtick位置。
有人知道如何處理Bbox,或簡單的方法來指定這些刻度?