我正在为特定实验构建一类绘图工具。我目前有两种绘图方法,一个使用 imshow() 的静态绘图,以及一个也使用 imshow() 的“电影”格式。
对于我可能编写的任何特定绘图方法,方法和任何未来的方法都获得相同的参数。在使用绘图类时,我在配置对象中拥有所有这些参数。
我不想在每个绘图方法中重写代码。我想初始化一个将设置这些参数的对象(我认为是 AxesImage):vmin、vmax、extent_dim、Xlocs、Xlabels、Ylocs、Ylabels。
然后我只是将该对象传递给执行其他特定操作的各种方法。我不明白如何做到这一点...
import matplotlib.pyplot as plt
data = data_dict[type] # could be real part of a complex number, phase, or the mag...
v_min, v_max = self.get_data_type_scale(data_dict, Type)
freq = data_dict['freq']
# essentially sets the aspect of the plot since the x and y resolutions could be different
extent_dim = self._get_extent(2)
# gets the labels for physical dimensions of the experiment
Xlocs,Xlabels,Ylocs,Ylabels = self._get_ticks(5,5,extent_dim)
# in the guts of a plot method, the basic idea is the call below.
plt.imshow(data[0,:,:],cmap='jet',vmin=v_min,...
vmax=v_max,origin='lower', extent = extent_dim)
plt.title('Type: %s Freq: %.3e Hz' %(Type,data_dict['freq'][0]) )
plt.xticks(Xlocs, Xlabels)
plt.yticks(Ylocs,Ylabels)