1

我有一组数据,代表一段时间内多个点的热电偶值。使用 Chaco,我设法绘制了热电偶位置的热图,并带有一个滑块,可以让我选择我想要显示的时间步长。这样做的目的是比较数据集如何随时间变化。

我遇到的问题是颜色图比例会根据屏幕上显示的最大值和最小值而变化,但我希望颜色图比例保持固定在预定的最小值和最大值。有没有使用 Chaco 和 Traits 的简单方法来做到这一点?我查看了 Chaco 文档,但我找到的示例都没有涵盖这种情况。

为简单起见,这里是我的代码的精简副本。我用相同形状的生成数据集替换了我的数据,具有相同的最小值和最大值。

import numpy as np
from enable.api import *
from chaco.shell import *
from traits.api import *
from traitsui.api import *
from chaco.api import *
from chaco.tools.api import *

## Random Data
data11 = np.ones([3,5,100])
print data11.shape
for i in range(3):
    for j in range(5):
        for k in range(100):
            data11[i,j,k] = np.random.random_integers(1100)

class heatplots(HasTraits):
    plot = Instance(Plot)
    time = Range(1,99)

    traits_view = View(Item('time'),
                        Item('plot', editor=ComponentEditor()),
                        width=1000, height=600, resizable=True, title='heatmap')


    def datamaker(self):  ## Setting the data time
        t = self.time

        ## Defining the data picker sources
        self.data = data11[...,...,t]

    def heatplotter(self):  ##Making the Plots
        ## The first heatmap                
        self.plotdata1 = ArrayPlotData(hm1 = self.data)
        plot1 = Plot(self.plotdata1)
        plot1.img_plot("hm1", colormap=hot)
        self.plot = plot1

    #_heatplotter()  
    @on_trait_change('time')
    def _new_time(self):
        self.datamaker()
        self.heatplotter()

    def start(self):        
        self._new_time()
        self.configure_traits()

thing = heatplots()
thing.start()

如果我的某些格式看起来很奇怪或迂回,可能是因为我的完整绘图包括一个数据选择器,我可以在其中选择数据集,并且它在 HPlotContainer 中并排有 2 个热图。我已将其删除,因为它与我的问题无关。

感谢您的时间。

4

0 回答 0