Issue with barchart using traits
seraf-m opened this issue · 0 comments
When using traits to make an interactive barchart, the 's' input to the barchart function does not update upon changing a trait in the ui; I have put together a minimal example I attach below. To reproduce, interchange the 's' and 'z' arguments on line 27.
At least on my machine, when that line (the else
case in the **update
function) spells
self.plot.mlab_source.trait_set(x=self.xs, y=self.ys, s=self.zs, z=radialsine(self.xs,self.ys,self.delta))
,
the z values update nicely and the bars float to their specified positions, while the update to s is ignored (which is opposite of what im trying to do, I'd like to keep z at 0 and change the values of the bars).
I tried pretty much everything I could think of, changing order of arguments, trying the different number of arguments supplied to barchart etc., to no avail.
bartest.txt
I am new to reporting issues on github, if it would be more desireable to have the code in a .txt file, please let me know.
package versions:
mayavi==4.8.2
traits==6.4.3
traitsui==8.0.0
vtk==9.3.1
QtPy==2.4.1
PyQt5==5.15.11
PyQt5-Qt5==5.15.2
PyQt5_sip==12.15.0
pyface==8.0.0
import numpy as np
from mayavi import mlab
from traits.api import HasTraits, Range, Instance, on_trait_change
from traitsui.api import View, Item, Group
from mayavi.core.api import PipelineBase
from mayavi.core.ui.api import MayaviScene, SceneEditor, MlabSceneModel
def radialsine(x,y,delta=0):
return np.sin(np.sqrt(x**2+y**2)+delta)
class bartest(HasTraits):
delta = Range(-np.pi,np.pi,0.)
scene = Instance(MlabSceneModel, ())
plot = Instance(PipelineBase)
xs,ys=np.mgrid[-2:2:10j,-2:2:10j]
zs=np.zeros_like(xs)
def __init__(self):
HasTraits.__init__(self)
self.scene.background, self.scene.foreground = (1,1,1), (0,0,0)
@on_trait_change('delta, scene.activated')
def update(self):
if self.plot is None:
self.plot = self.scene.mlab.barchart(self.xs, self.ys, self.zs, radialsine(x=self.xs,y=self.ys,delta=self.delta), vmax=1,vmin=-1,lateral_scale=0.3,colormap='viridis',figure=self.scene.mayavi_scene)
else:
self.plot.mlab_source.trait_set(x=self.xs, y=self.ys, s=self.zs, z=radialsine(self.xs,self.ys,self.delta))
view = View(Item('scene', editor=SceneEditor(scene_class=MayaviScene), height=250, width=300, show_label=False),
Item('delta'))#, format_str='%.2f', editor_args={'low_label':'-π', 'high_label':' π'}))
my_model = bartest()
my_model.configure_traits()