Search code examples
pythonplotlyprojection-matrix

How to add interval or condition on Z Projection on 3D Plot from Plotly (Python)?


I'm trying to plot a matrix with a z projection but I don't want to project at each 0.5 values like below.

Matrix 3D Plotting with Z Projection

I want to project the values that are "< 7.5" for example but I don't know if it's possible with Plotly Library on Python.

If someone knows how to deal with it, I would be grateful

Here is the code I've tried:


    def plotIntensity3D(self):
        z = self.matrix # Numpy 2D array with values between 5.4 and 8.2

        fig = go.Figure(data=[go.Surface(z=z, cmin=7,cmax=8.5)])
        # fig.update_traces(colorscale = [[0, 'rgb(255,0,0)'], [1, 'rgb(0,255,0)']])
        fig.update_traces(contours_z=dict(show=True, usecolormap=True, highlightcolor="limegreen", project_z=True))
        fig.update_layout(title='3D Light Intensity', autosize=True, width=1000, height=1000)
        
        fig.show()

Solution

  • Add something like this to update_layout:

    scene = dict(
                 xaxis = dict(nticks=9, range=[0,80],),
                 yaxis = dict(nticks=7, range=[0,120],),
                 zaxis = dict(nticks=4, range=[5,8],),
                 ),