Overlay Multiple Plot Types

I am trying to overlay multiple plots on top of each other, specifically overlaying a ternary scatter plot on top of a ternary contour plot. I have seen some documentation showing how to overlay multiple traces, but I cannot seem to get it to work for this case where the plots are of different types (plotly.figure_factory.create_ternary_contour and plotly.express.scatter_ternary).

Of note, I am not trying to display the data points that generate the contour plot, I want to plot an entirely separate set of data on top of the contour plot, using the same axes.

Thank you for any help you can give me!

I’m not exactly sure if I did understood fully your problematic.

If you have a minimal working example of what you tried, it might help to get your precise goal.

Here is a MWE showing how to overlay 2 traces of 2 different graph type from 2 different data set :

suppressMessages(library(plotly))

myData1 <-  data.frame ("X"=1:10, "Y"=runif(10))
myData2 <-  data.frame ("X"=1:10, "Y"=runif(10))

fig <-  plot_ly()

fig <- add_trace(
   fig,
   type = 'scatter',
   mode = 'line',
   x = myData1$X,
   y = myData1$Y
)

fig <- add_trace(
   fig,
   type = 'bar',
   x = myData2$X,
   y = myData2$Y
)

htmlwidgets::saveWidget(as_widget(fig), "mwe.html")

Tell me if it does help you to successfully overlay your scatter and contour plot :slight_smile: .

1 Like

Thanks for the help. Sorry, I’m pretty new to plotly, and maybe it’s helpful to clarify that I’m trying to do this in python (which I’m also pretty new to).

Essentially I have two plots that I am able to make separately, one that is a ternary scatter plot, made following the instructions from this page (https://plotly.com/python/ternary-plots/), specifically the ‘Ternary scatter plots with Plotly Express’ section. The other plot is a contour heatmap made with plotly figure factory based on this page (https://plotly.com/python/ternary-contour/). The two plots are generated for the same set of axes, but based on unique sets of data.

Since I originally posted this I’ve been looking into it more and I’m wondering now if both plots can be made using plotly graph objects and if that would simplify their merger. For example, using the code provided for contour plots here (https://plotly.com/python/ternary-scatter-contour/) and for ‘Ternary scatter plots with Graph Objects’ here (https://plotly.com/python/ternary-plots/). I’m not sure if that actually makes sense, however.

Ok, your question is posted with the tag “plotly.R” and not “plotly.py”, you might get a better answer by posting it with the right tag.

Nevertheless, if you share your minimal working exemple, I can try to help you with an exemple in python :slight_smile: