Plotly.py: slight change in surface opacity changes image completely

Created on 5 Aug 2020  路  6Comments  路  Source: plotly/plotly.py

I need to adjust the opacity of a surface, so I can overlay two surfaces on top of each other (not sure how else to do that). But on a very small change from 1 to slightly below the look of the plot changes a lot.

opacity=1
image

opacity=0.99999
image

import numpy as np
from plotly.graph_objs import Figure, Surface

x = np.array(
    [
        [0, 0, 0, 0, 0, 0, 0, 0, 0],
        [
            7.07106781e-01,
            0.5,
            4.32978028e-17,
            -0.5,
            -7.07106781e-01,
            -0.5,
            -1.29893408e-16,
            0.5,
            7.07106781e-01,
        ],
        [
            1,
            7.07106781e-01,
            6.12323400e-17,
            -7.07106781e-01,
            -1,
            -7.07106781e-01,
            -1.83697020e-16,
            7.07106781e-01,
            1,
        ],
        [
            7.07106781e-01,
            0.5,
            4.32978028e-17,
            -0.5,
            -7.07106781e-01,
            -0.5,
            -1.29893408e-16,
            0.5,
            7.07106781e-01,
        ],
        [
            1.22464680e-16,
            8.65956056e-17,
            7.49879891e-33,
            -8.65956056e-17,
            -1.22464680e-16,
            -8.65956056e-17,
            -2.24963967e-32,
            8.65956056e-17,
            1.22464680e-16,
        ],
    ]
)
y = np.array(
    [
        [0, 0, 0, 0, 0, -0, -0, -0, 0],
        [0, 0.5, 7.07106781e-01, 0.5, 8.65956056e-17, -0.5, -7.07106781e-01, -0.5, 0],
        [
            0,
            7.07106781e-01,
            1,
            7.07106781e-01,
            1.22464680e-16,
            -7.07106781e-01,
            -1,
            -7.07106781e-01,
            0,
        ],
        [0, 0.5, 7.07106781e-01, 0.5, 8.65956056e-17, -0.5, -7.07106781e-01, -0.5, 0],
        [
            0,
            8.65956056e-17,
            1.22464680e-16,
            8.65956056e-17,
            1.49975978e-32,
            -8.65956056e-17,
            -1.22464680e-16,
            -8.65956056e-17,
            0,
        ],
    ]
)
z = np.array(
    [
        [1, 1, 1, 1, 1, 1, 1, 1, 1],
        [
            7.07106781e-01,
            7.07106781e-01,
            7.07106781e-01,
            7.07106781e-01,
            7.07106781e-01,
            7.07106781e-01,
            7.07106781e-01,
            7.07106781e-01,
            7.07106781e-01,
        ],
        [
            6.12323400e-17,
            6.12323400e-17,
            6.12323400e-17,
            6.12323400e-17,
            6.12323400e-17,
            6.12323400e-17,
            6.12323400e-17,
            6.12323400e-17,
            6.12323400e-17,
        ],
        [
            -7.07106781e-01,
            -7.07106781e-01,
            -7.07106781e-01,
            -7.07106781e-01,
            -7.07106781e-01,
            -7.07106781e-01,
            -7.07106781e-01,
            -7.07106781e-01,
            -7.07106781e-01,
        ],
        [-1, -1, -1, -1, -1, -1, -1, -1, -1],
    ]
)
data = [Surface(x=x, y=y, z=z, surfacecolor=np.ones(x.shape), opacity=0.99999)]
fig = Figure(data=data)
fig.show()

sorry about the numbers, they've been generated by some external library

my actual use case is like this where there are weird lines appearing on the plot by setting opacity
image

All 6 comments

@archmoj can you comment please?

@paddyroddy could you please set the opacity to 0.25 or 0.5 and share new screenshots?

opacity=0.5
image

and in my more complicated use-case with opacity=0.5
image

Here is a demo in codepen.
Wondering if you tried using mesh3d instead of surface plot for that kind of geometry?

This could possibly be fixed/improved by https://github.com/plotly/plotly.js/pull/4643.
But at the moment I don't see that PR being merged in near feature.

Here is a demo in codepen.
Wondering if you tried using mesh3d instead of surface plot for that kind of geometry?

thanks, no I haven't. My actual data is spherical (the example was low resolution) and isn't one uniform colour I have a surfacecolor passed to it. So not sure whether mesh3d would achieve the same thing

Was this page helpful?
0 / 5 - 0 ratings