set_xlim,set_ylim,set_zlim commands in matplotlib fail to clip displayed data

前端 未结 2 1585
情歌与酒
情歌与酒 2020-12-20 19:55

I\'m building a GUI with Tkinter and ttk and using matplotlib in order to creat interactive plots - again, like millions other people do. Even though most problems I encount

相关标签:
2条回答
  • 2020-12-20 20:34

    Following code works even for meshgrid data representation:

    @ numpy.vectorize
    def clip_z_data(z):
      return z if Z_MIN <= z <= Z_MAX else n.nan
    
    z = clip_z_data(z)
    

    Z_MIN and Z_MAX are global, because vectorize can't handle extra attributes.

    0 讨论(0)
  • 2020-12-20 20:37

    The Problem here is, that mplot3d has no OpenGL backend. The calculations for displaying the data are thus based on 2d. I found the same issue here and a workaround here. Even though the workaround is not the best in my opinion because it depends on the resolution of your data.

    I followed the second link anyway. So, what I'm doing now is copying the array and setting all the values above and under my desired scale to NaN. When plotting those, the lines will be cut off where the datapoints exceed the desired limit.

    def SetAxis2(self):
        self.dummyx=CL.x*1
        self.dummyy=CL.y*1
        self.dummyz=CL.z*1
        #clipping manually
        for i in nm.arange(len(self.dummyx)):
            if self.dummyx[i] < self.x1:
                self.dummyx[i] = nm.NaN
            else:
                pass
    
        for i in nm.arange(len(self.dummyy)):
            if self.dummyy[i] < self.y1:
                self.dummyy[i] = nm.NaN
            else:
                pass
    
        for i in nm.arange(len(self.dummyz)):
            if self.dummyz[i] < self.z1:
                self.dummyz[i] = nm.NaN
            else:
                pass     
    
        controlset.a.plot(self.dummyx,\
        self.dummyy,\
        self.dummyz)
    
        self.a.set_xlim3d(self.x1, self.x2)
        self.a.set_ylim3d(self.y1, self.y2)
        self.a.set_zlim3d(self.z1, self.z2)
    

    If now your scale is set from 0 to 10 and you have six datapoints: [-1, 3 4 12 5 1] The line will go from 3 to 4 and 5 to 1 because -1 and 12 will be set to NaN. An improvement regarding that problem would be good. Mayavi might be better, but I haven't tried this as I wanted to stick with matplotlib.

    0 讨论(0)
提交回复
热议问题