Skip to main content
2 of 8
added 108 characters in body
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

Programmatically combine 2D contour plots with 1D projections

I regularly need to plot 2D and 1D data together. I want to be able to show a 2D contour plot with the projections along each of the axes. As it is now, I create the three plots separately and use Inkscape to combine them. The problem with this is twofold. First, it is cumbersome if I have to do it over and over. Second, I have to use my eyes to move the 1D plot so that its features line up properly with the 2D data.

As a simple working example, consider this 2D array of data

xrange = {8, 19}; yrange = {6, 16}; twoDlist = Table[Abs[ I/(ω1 - 14 + I) I/(ω2 - 11 + I) + ( I/3)/(ω1 - 8 + I/3) I/(ω2 - 16 + I)], {ω1, yrange[[1]], yrange[[2]], .05}, {ω2, xrange[[1]], xrange[[2]], .05}]; 

From this I generate the 2D and 1D plots.

topplot = ListLinePlot[Total[twoDlist], Axes -> False, DataRange -> xrange, PlotStyle -> {{Thick, Red}}, PlotRange -> {Full, All}]; rightplot = ListLinePlot[Total /@ twoDlist, Axes -> False, DataRange -> yrange, PlotStyle -> {{Thick, Red}}, PlotRange -> All]; contourplot = ListContourPlot[twoDlist, DataRange -> {xrange, yrange}, ContourShading -> None, Contours -> 20, PlotRange -> {Full, Full, All}, ContourStyle -> Table[Blend[{Blue, Green, Yellow, Red}, n], {n, .05, 1, .05}]]; 

Now I would like to combine them in such a way to get an image like this one:

enter image description here

How can I do this? Ideally, I want to end up with a plotting function that takes twoDlist, xrange, and yrange as arguments.

Thanks in advance.

user4368
  • 72.3k
  • 3
  • 152
  • 317