# Plot ordering with scatter and contours

**URL:** <https://community.plotly.com/t/plot-ordering-with-scatter-and-contours/8875>\
**Category:** 📊 Plotly Python\
**Created:** [March 9, 2018, 9:41am UTC](https://community.plotly.com/t/plot-ordering-with-scatter-and-contours/8875 "2018-03-09T09:41:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![razgmaz](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@razgmaz](https://community.plotly.com/u/razgmaz)\
**Post date:** [March 9, 2018, 9:41am UTC](https://community.plotly.com/t/plot-ordering-with-scatter-and-contours/8875/1 "2018-03-09T09:41:43Z")

</div>

Hi,

I am trying to plot a contour plot of a probability density function and a scatter plot of the data points generated from this distribution. However, for large data sets, the contour plot is not exactly visible because the data points are plotted over it.

So, I was trying to figure out how to change the order of plotting. I noticed that if I have only scatter plots, then the ordering in the data list is influencing the order of plotting but that is not the case when I have the aforementioned contour plot. Scatter plots are always over the contour plot.

Here’s the code I’ve been writing:  
import numpy as np

```
import plotly as py
import plotly.graph_objs as go

X = np.arange(-5, 5, 0.1)
Y = np.arange(0, 4, 0.1)
x, y = np.meshgrid(X, Y)
p = mlab.bivariate_normal(x, y, 1.5, 0.8, 1, 2, 0.6)
mean_pre = np.array([1,2])
cov_pre = np.array([[1.5**2, 0.6],[0.6, 0.8**2]])
sample = np.random.multivariate_normal(mean_pre, cov_pre, 10000).T

py.offline.init_notebook_mode(connected=True)
layout = go.Layout(
    title='True Distribution and Sampled Data Points',
    yaxis=dict(
        title='x'
    ),
    xaxis=dict(
        title='y'
    )
)
trace1 = go.Scattergl(
    x=sample[0], 
    y=sample[1],
    mode='markers',
    name='Sampled Data',
    marker = dict(
        size = 2,
        opacity = 0.6
    )
)

contours = go.Contour(
        z=p,
        x=X,
        y=Y,
        colorscale='Jet',
        contours=dict(
            coloring='lines',
        ),
        line = dict(
            width=2
        )
    )

fig = go.Figure(data=[trace1, contours], layout=layout)
py.offline.iplot(fig)`
```

---

<div class="post-metadata">

**Author:** ![tfg250](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@tfg250](https://community.plotly.com/u/tfg250)\
**Post date:** [March 19, 2020, 1:17am UTC](https://community.plotly.com/t/plot-ordering-with-scatter-and-contours/8875/2 "2020-03-19T01:17:02Z")

</div>

Same behavior still exists 2 years later. It would be nice to have a “zorder” parameter.
