Skip to main content
data1 = Table[
   1.*a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[b])^2/(2 sy^2 + 
             RandomReal[{0, 1}])) - ((-mx + x) Cos[b] + (-my + y) Sin[
              b])^2/(2 sx^2 + RandomReal[{0, 1}])) /. {a -> 1, 
     my -> -1, mx -> -4, sx -> 2, sy -> 2, b -> 7 \[Pi]π/3}, {x, -10, 
    10, 1}, {y, -10, 10, 1}];
Coolplot[data1_] := 
 Module[{data, dataf, sx0, sy0, mx0, my0, fm, bsparameters, sigmaplot,
    marginal1, marginal2, final, central, c},
  
  data = Table[{x, y, data1[[x, y]]}, {x, 1, Length@data1[[1]]}, {y, 
     1, Length@data1[[All, 1]]}];
  dataf = Flatten[data, 1];
  sx0 = Max[Map[StandardDeviation[#[[All, 3]]] &, data]];
  sy0 = Max[Map[StandardDeviation[#[[All, 3]]] &, Transpose[data]]];
  {mx0, my0} = 
   Extract[dataf, Position[dataf[[All, 3]], Max[dataf[[All, 3]]]]][[
    1, {1, 2}]];
  fm = Quiet@
    NonlinearModelFit[dataf, 
     a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[
                 b])^2/(2 sy^2)) - ((-mx + x) Cos[b] + (-my + y) Sin[
               b])^2/(2 sx^2)), {{a, 0.1}, {b, 0}, {mx, mx0}, {my, 
       my0}, {sx, sx0}, {sy, sy0}}, {x, y}];
  bsparameters = fm["BestFitParameters"];
  c[t_, n_] := {mx + Cos[b] (n sx Cos[t]) - Sin[b] (n sy Sin[t]), 
     my + (n sx Cos[t]) Sin[b] + Cos[b] (n sy Sin[t])} /. bsparameters;
  sigmaplot[n_, color_] := 
   ParametricPlot[c[t, n], {t, 0, 2 \[Pi]π}, 
    PlotStyle -> {Thick, color, Dashed}];
  
  
  
  central = 
   ListContourPlot[dataf, PlotRange -> All /. bsparameters, 
    ColorFunction -> "DeepSeaColors", 
    PlotLegends -> 
     Placed[BarLegend["DeepSeaColors", LegendLayout -> "Row", 
       LegendMarkerSize -> 390], Below], ImageSize -> 377];
  marginal1 = 
   ListLinePlot[
    Transpose[{Reverse@Map[#[[1, 2]] &, Transpose[data]], 
      Map[Total@#[[All, 3]] &, Transpose[data]]}], Frame -> True, 
    AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, 
    Filling -> Bottom, ColorFunction -> "DeepSeaColors", 
    FrameTicks -> {None, Automatic}];
  marginal2 = 
   ListLinePlot[Map[{#[[1, 1]], Total@#[[All, 3]]} &, data], 
    Frame -> True, AspectRatio -> 1/4, PlotRange -> All, 
    InterpolationOrder -> 0, Filling -> Bottom, 
    ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}];
  final = 
   Graphics[{Inset[
      Show[{central, sigmaplot[1, Red](*,Epilog\[Rule]{Arrow[{c[0,
        1],.93c[0,1]}],Text[Style[Subscript[\[Sigma]Text[Style[Subscript[σ, 1],Red],.93c[0,
        1]]}*)}, PlotRange -> All], {101.5, 
       20 + 150 + 85 + 10}, {Center, Center}, {150, 170}], 
     Rotate[Inset[
       marginal1, {100 + 24, 150 + 85 + 45}, {Left, Center}, {145, 
        50}], 3 \[Pi]π/2], 
     Inset[marginal2, {101, 150 + 85 + 10 + 124}, {Center, 
       Center}, {148, 40}]}, ImageSize -> 500];
  Magnify[final, 1.5]
  ]
data1 = Table[
   1.*a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[b])^2/(2 sy^2 + 
             RandomReal[{0, 1}])) - ((-mx + x) Cos[b] + (-my + y) Sin[
              b])^2/(2 sx^2 + RandomReal[{0, 1}])) /. {a -> 1, 
     my -> -1, mx -> -4, sx -> 2, sy -> 2, b -> 7 \[Pi]/3}, {x, -10, 
    10, 1}, {y, -10, 10, 1}];
Coolplot[data1_] := 
 Module[{data, dataf, sx0, sy0, mx0, my0, fm, bsparameters, sigmaplot,
    marginal1, marginal2, final, central, c},
  
  data = Table[{x, y, data1[[x, y]]}, {x, 1, Length@data1[[1]]}, {y, 
     1, Length@data1[[All, 1]]}];
  dataf = Flatten[data, 1];
  sx0 = Max[Map[StandardDeviation[#[[All, 3]]] &, data]];
  sy0 = Max[Map[StandardDeviation[#[[All, 3]]] &, Transpose[data]]];
  {mx0, my0} = 
   Extract[dataf, Position[dataf[[All, 3]], Max[dataf[[All, 3]]]]][[
    1, {1, 2}]];
  fm = Quiet@
    NonlinearModelFit[dataf, 
     a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[
                 b])^2/(2 sy^2)) - ((-mx + x) Cos[b] + (-my + y) Sin[
               b])^2/(2 sx^2)), {{a, 0.1}, {b, 0}, {mx, mx0}, {my, 
       my0}, {sx, sx0}, {sy, sy0}}, {x, y}];
  bsparameters = fm["BestFitParameters"];
  c[t_, n_] := {mx + Cos[b] (n sx Cos[t]) - Sin[b] (n sy Sin[t]), 
     my + (n sx Cos[t]) Sin[b] + Cos[b] (n sy Sin[t])} /. bsparameters;
  sigmaplot[n_, color_] := 
   ParametricPlot[c[t, n], {t, 0, 2 \[Pi]}, 
    PlotStyle -> {Thick, color, Dashed}];
  
  
  
  central = 
   ListContourPlot[dataf, PlotRange -> All /. bsparameters, 
    ColorFunction -> "DeepSeaColors", 
    PlotLegends -> 
     Placed[BarLegend["DeepSeaColors", LegendLayout -> "Row", 
       LegendMarkerSize -> 390], Below], ImageSize -> 377];
  marginal1 = 
   ListLinePlot[
    Transpose[{Reverse@Map[#[[1, 2]] &, Transpose[data]], 
      Map[Total@#[[All, 3]] &, Transpose[data]]}], Frame -> True, 
    AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, 
    Filling -> Bottom, ColorFunction -> "DeepSeaColors", 
    FrameTicks -> {None, Automatic}];
  marginal2 = 
   ListLinePlot[Map[{#[[1, 1]], Total@#[[All, 3]]} &, data], 
    Frame -> True, AspectRatio -> 1/4, PlotRange -> All, 
    InterpolationOrder -> 0, Filling -> Bottom, 
    ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}];
  final = 
   Graphics[{Inset[
      Show[{central, sigmaplot[1, Red](*,Epilog\[Rule]{Arrow[{c[0,
        1],.93c[0,1]}],Text[Style[Subscript[\[Sigma], 1],Red],.93c[0,
        1]]}*)}, PlotRange -> All], {101.5, 
       20 + 150 + 85 + 10}, {Center, Center}, {150, 170}], 
     Rotate[Inset[
       marginal1, {100 + 24, 150 + 85 + 45}, {Left, Center}, {145, 
        50}], 3 \[Pi]/2], 
     Inset[marginal2, {101, 150 + 85 + 10 + 124}, {Center, 
       Center}, {148, 40}]}, ImageSize -> 500];
  Magnify[final, 1.5]
  ]
data1 = Table[
   1.*a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[b])^2/(2 sy^2 + 
             RandomReal[{0, 1}])) - ((-mx + x) Cos[b] + (-my + y) Sin[
              b])^2/(2 sx^2 + RandomReal[{0, 1}])) /. {a -> 1, 
     my -> -1, mx -> -4, sx -> 2, sy -> 2, b -> 7 π/3}, {x, -10, 
    10, 1}, {y, -10, 10, 1}];
Coolplot[data1_] := 
 Module[{data, dataf, sx0, sy0, mx0, my0, fm, bsparameters, sigmaplot,
    marginal1, marginal2, final, central, c},
  
  data = Table[{x, y, data1[[x, y]]}, {x, 1, Length@data1[[1]]}, {y, 
     1, Length@data1[[All, 1]]}];
  dataf = Flatten[data, 1];
  sx0 = Max[Map[StandardDeviation[#[[All, 3]]] &, data]];
  sy0 = Max[Map[StandardDeviation[#[[All, 3]]] &, Transpose[data]]];
  {mx0, my0} = 
   Extract[dataf, Position[dataf[[All, 3]], Max[dataf[[All, 3]]]]][[
    1, {1, 2}]];
  fm = Quiet@
    NonlinearModelFit[dataf, 
     a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[
                 b])^2/(2 sy^2)) - ((-mx + x) Cos[b] + (-my + y) Sin[
               b])^2/(2 sx^2)), {{a, 0.1}, {b, 0}, {mx, mx0}, {my, 
       my0}, {sx, sx0}, {sy, sy0}}, {x, y}];
  bsparameters = fm["BestFitParameters"];
  c[t_, n_] := {mx + Cos[b] (n sx Cos[t]) - Sin[b] (n sy Sin[t]), 
     my + (n sx Cos[t]) Sin[b] + Cos[b] (n sy Sin[t])} /. bsparameters;
  sigmaplot[n_, color_] := 
   ParametricPlot[c[t, n], {t, 0, 2 π}, 
    PlotStyle -> {Thick, color, Dashed}];
  
  
  
  central = 
   ListContourPlot[dataf, PlotRange -> All /. bsparameters, 
    ColorFunction -> "DeepSeaColors", 
    PlotLegends -> 
     Placed[BarLegend["DeepSeaColors", LegendLayout -> "Row", 
       LegendMarkerSize -> 390], Below], ImageSize -> 377];
  marginal1 = 
   ListLinePlot[
    Transpose[{Reverse@Map[#[[1, 2]] &, Transpose[data]], 
      Map[Total@#[[All, 3]] &, Transpose[data]]}], Frame -> True, 
    AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, 
    Filling -> Bottom, ColorFunction -> "DeepSeaColors", 
    FrameTicks -> {None, Automatic}];
  marginal2 = 
   ListLinePlot[Map[{#[[1, 1]], Total@#[[All, 3]]} &, data], 
    Frame -> True, AspectRatio -> 1/4, PlotRange -> All, 
    InterpolationOrder -> 0, Filling -> Bottom, 
    ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}];
  final = 
   Graphics[{Inset[
      Show[{central, sigmaplot[1, Red](*,Epilog\[Rule]{Arrow[{c[0,
        1],.93c[0,1]}],Text[Style[Subscript[σ, 1],Red],.93c[0,
        1]]}*)}, PlotRange -> All], {101.5, 
       20 + 150 + 85 + 10}, {Center, Center}, {150, 170}], 
     Rotate[Inset[
       marginal1, {100 + 24, 150 + 85 + 45}, {Left, Center}, {145, 
        50}], 3 π/2], 
     Inset[marginal2, {101, 150 + 85 + 10 + 124}, {Center, 
       Center}, {148, 40}]}, ImageSize -> 500];
  Magnify[final, 1.5]
  ]
Capitalization
Source Link
Jacob Akkerboom
  • 12.2k
  • 46
  • 82

I love making plots in MathematicaMathematica. And iI love to spend a lot of time making high-quality plots that maximize readability and aesthetics. For most cases, mathematicaMathematica can make very beautiful images, but when iI see Python-seaborn plots iI really lovedlove the aestheticaesthetics. For example, the density-contour plots. Here is a pythonPython-seaborn example:

I have spent too many hours trying to recreate this plots in MathematicaMathematica with no success. So my question is: there isIs there a way to recreate the whole style of thisthese plots (at least the two in this question) in MathematicaMathematica?.

The color schemes are one of the things that iI manage very bad. I understand that there is some opacity and transparency involved in the colors but iI am really really bad at this, so iI cannot help very much in this aspect.

This data using $ListContourPlot$ListContourPlot looks like:

As requested in the comments iI attached a starter code to the second plot:

Defining a gaussianGaussian-like dataset:

To spawn the plot use:

I love making plots in Mathematica. And i love to spend a lot of time making high-quality plots that maximize readability and aesthetics. For most cases, mathematica can make very beautiful images, but when i see Python-seaborn plots i really loved the aesthetic. For example, the density-contour plots. Here is a python-seaborn example:

I have spent too many hours trying to recreate this plots in Mathematica with no success. So there is a way to recreate the whole style of this plots (at least the two in this question) in Mathematica?.

The color schemes are one of the things that i manage very bad. I understand that there is some opacity and transparency involved in the colors but i am really really bad at this, so i cannot help very much in this aspect.

This data using $ListContourPlot$ looks like:

As requested in the comments i attached a starter code to the second plot:

Defining a gaussian-like dataset:

To spawn the plot use

I love making plots in Mathematica. And I love to spend a lot of time making high-quality plots that maximize readability and aesthetics. For most cases, Mathematica can make very beautiful images, but when I see Python-seaborn plots I really love the aesthetics. For example, the density-contour plots. Here is a Python-seaborn example:

I have spent too many hours trying to recreate this plots in Mathematica with no success. So my question is: Is there a way to recreate the whole style of these plots (at least the two in this question) in Mathematica?

The color schemes are one of the things that I manage very bad. I understand that there is some opacity and transparency involved in the colors but I am really really bad at this, so I cannot help very much in this aspect.

This data using ListContourPlot looks like:

As requested in the comments I attached a starter code to the second plot:

Defining a Gaussian-like dataset:

To spawn the plot use:

added 233 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

data = BinCounts[ Select[RandomReal[ NormalDistribution[0, 1], {10^5, 2}], -3 <= #[1] <= 3 && -3 <= #[2] <= 3 &], 0.1, 0.1];

data = BinCounts[
   Select[RandomReal[
     NormalDistribution[0, 1], {10^5, 
      2}], -3 <= #[[1]] <= 3 && -3 <= #[[2]] <= 3 &], 0.1, 0.1];

data1 = Table[ 1.*a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[b])^2/(2 sy^2 + RandomReal[{0, 1}])) - ((-mx + x) Cos[b] + (-my + y) Sin[ b])^2/(2 sx^2 + RandomReal[{0, 1}])) /. {a -> 1, my -> -1, mx -> -4, sx -> 2, sy -> 2, b -> 7 [Pi]/3}, {x, -10, 10, 1}, {y, -10, 10, 1}];

data1 = Table[
   1.*a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[b])^2/(2 sy^2 + 
             RandomReal[{0, 1}])) - ((-mx + x) Cos[b] + (-my + y) Sin[
              b])^2/(2 sx^2 + RandomReal[{0, 1}])) /. {a -> 1, 
     my -> -1, mx -> -4, sx -> 2, sy -> 2, b -> 7 \[Pi]/3}, {x, -10, 
    10, 1}, {y, -10, 10, 1}];

Coolplot[data1_] := Module[{data, dataf, sx0, sy0, mx0, my0, fm, bsparameters, sigmaplot, marginal1, marginal2, final, central, c},

data = Table[{x, y, data1[[x, y]]}, {x, 1, Length@data1[1]}, {y, 1, Length@data1[[All, 1]]}]; dataf = Flatten[data, 1]; sx0 = Max[Map[StandardDeviation[#[[All, 3]]] &, data]]; sy0 = Max[Map[StandardDeviation[#[[All, 3]]] &, Transpose[data]]]; {mx0, my0} = Extract[dataf, Position[dataf[[All, 3]], Max[dataf[[All, 3]]]]][[ 1, {1, 2}]]; fm = Quiet@ NonlinearModelFit[dataf, a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[ b])^2/(2 sy^2)) - ((-mx + x) Cos[b] + (-my + y) Sin[ b])^2/(2 sx^2)), {{a, 0.1}, {b, 0}, {mx, mx0}, {my, my0}, {sx, sx0}, {sy, sy0}}, {x, y}]; bsparameters = fm["BestFitParameters"]; c[t_, n_] := {mx + Cos[b] (n sx Cos[t]) - Sin[b] (n sy Sin[t]), my + (n sx Cos[t]) Sin[b] + Cos[b] (n sy Sin[t])} /. bsparameters; sigmaplot[n_, color_] := ParametricPlot[c[t, n], {t, 0, 2 [Pi]}, PlotStyle -> {Thick, color, Dashed}];

central = ListContourPlot[dataf, PlotRange -> All /. bsparameters, ColorFunction -> "DeepSeaColors", PlotLegends -> Placed[BarLegend["DeepSeaColors", LegendLayout -> "Row", LegendMarkerSize -> 390], Below], ImageSize -> 377]; marginal1 = ListLinePlot[ Transpose[{Reverse@Map[#[[1, 2]] &, Transpose[data]], Map[Total@#[[All, 3]] &, Transpose[data]]}], Frame -> True, AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, Filling -> Bottom, ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}]; marginal2 = ListLinePlot[Map[{#[[1, 1]], Total@#[[All, 3]]} &, data], Frame -> True, AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, Filling -> Bottom, ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}]; final = Graphics[{Inset[ Show[{central, sigmaplot[1, Red](,Epilog[Rule]{Arrow[{c[0, 1],.93c[0,1]}],Text[Style[Subscript[[Sigma], 1],Red],.93c[0, 1]]})}, PlotRange -> All], {101.5, 20 + 150 + 85 + 10}, {Center, Center}, {150, 170}], Rotate[Inset[ marginal1, {100 + 24, 150 + 85 + 45}, {Left, Center}, {145, 50}], 3 [Pi]/2], Inset[marginal2, {101, 150 + 85 + 10 + 124}, {Center, Center}, {148, 40}]}, ImageSize -> 500]; Magnify[final, 1.5] ]

Coolplot[data1_] := 
 Module[{data, dataf, sx0, sy0, mx0, my0, fm, bsparameters, sigmaplot,
    marginal1, marginal2, final, central, c},
  
  data = Table[{x, y, data1[[x, y]]}, {x, 1, Length@data1[[1]]}, {y, 
     1, Length@data1[[All, 1]]}];
  dataf = Flatten[data, 1];
  sx0 = Max[Map[StandardDeviation[#[[All, 3]]] &, data]];
  sy0 = Max[Map[StandardDeviation[#[[All, 3]]] &, Transpose[data]]];
  {mx0, my0} = 
   Extract[dataf, Position[dataf[[All, 3]], Max[dataf[[All, 3]]]]][[
    1, {1, 2}]];
  fm = Quiet@
    NonlinearModelFit[dataf, 
     a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[
                 b])^2/(2 sy^2)) - ((-mx + x) Cos[b] + (-my + y) Sin[
               b])^2/(2 sx^2)), {{a, 0.1}, {b, 0}, {mx, mx0}, {my, 
       my0}, {sx, sx0}, {sy, sy0}}, {x, y}];
  bsparameters = fm["BestFitParameters"];
  c[t_, n_] := {mx + Cos[b] (n sx Cos[t]) - Sin[b] (n sy Sin[t]), 
     my + (n sx Cos[t]) Sin[b] + Cos[b] (n sy Sin[t])} /. bsparameters;
  sigmaplot[n_, color_] := 
   ParametricPlot[c[t, n], {t, 0, 2 \[Pi]}, 
    PlotStyle -> {Thick, color, Dashed}];
  
  
  
  central = 
   ListContourPlot[dataf, PlotRange -> All /. bsparameters, 
    ColorFunction -> "DeepSeaColors", 
    PlotLegends -> 
     Placed[BarLegend["DeepSeaColors", LegendLayout -> "Row", 
       LegendMarkerSize -> 390], Below], ImageSize -> 377];
  marginal1 = 
   ListLinePlot[
    Transpose[{Reverse@Map[#[[1, 2]] &, Transpose[data]], 
      Map[Total@#[[All, 3]] &, Transpose[data]]}], Frame -> True, 
    AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, 
    Filling -> Bottom, ColorFunction -> "DeepSeaColors", 
    FrameTicks -> {None, Automatic}];
  marginal2 = 
   ListLinePlot[Map[{#[[1, 1]], Total@#[[All, 3]]} &, data], 
    Frame -> True, AspectRatio -> 1/4, PlotRange -> All, 
    InterpolationOrder -> 0, Filling -> Bottom, 
    ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}];
  final = 
   Graphics[{Inset[
      Show[{central, sigmaplot[1, Red](*,Epilog\[Rule]{Arrow[{c[0,
        1],.93c[0,1]}],Text[Style[Subscript[\[Sigma], 1],Red],.93c[0,
        1]]}*)}, PlotRange -> All], {101.5, 
       20 + 150 + 85 + 10}, {Center, Center}, {150, 170}], 
     Rotate[Inset[
       marginal1, {100 + 24, 150 + 85 + 45}, {Left, Center}, {145, 
        50}], 3 \[Pi]/2], 
     Inset[marginal2, {101, 150 + 85 + 10 + 124}, {Center, 
       Center}, {148, 40}]}, ImageSize -> 500];
  Magnify[final, 1.5]
  ]

data = BinCounts[ Select[RandomReal[ NormalDistribution[0, 1], {10^5, 2}], -3 <= #[1] <= 3 && -3 <= #[2] <= 3 &], 0.1, 0.1];

data1 = Table[ 1.*a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[b])^2/(2 sy^2 + RandomReal[{0, 1}])) - ((-mx + x) Cos[b] + (-my + y) Sin[ b])^2/(2 sx^2 + RandomReal[{0, 1}])) /. {a -> 1, my -> -1, mx -> -4, sx -> 2, sy -> 2, b -> 7 [Pi]/3}, {x, -10, 10, 1}, {y, -10, 10, 1}];

Coolplot[data1_] := Module[{data, dataf, sx0, sy0, mx0, my0, fm, bsparameters, sigmaplot, marginal1, marginal2, final, central, c},

data = Table[{x, y, data1[[x, y]]}, {x, 1, Length@data1[1]}, {y, 1, Length@data1[[All, 1]]}]; dataf = Flatten[data, 1]; sx0 = Max[Map[StandardDeviation[#[[All, 3]]] &, data]]; sy0 = Max[Map[StandardDeviation[#[[All, 3]]] &, Transpose[data]]]; {mx0, my0} = Extract[dataf, Position[dataf[[All, 3]], Max[dataf[[All, 3]]]]][[ 1, {1, 2}]]; fm = Quiet@ NonlinearModelFit[dataf, a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[ b])^2/(2 sy^2)) - ((-mx + x) Cos[b] + (-my + y) Sin[ b])^2/(2 sx^2)), {{a, 0.1}, {b, 0}, {mx, mx0}, {my, my0}, {sx, sx0}, {sy, sy0}}, {x, y}]; bsparameters = fm["BestFitParameters"]; c[t_, n_] := {mx + Cos[b] (n sx Cos[t]) - Sin[b] (n sy Sin[t]), my + (n sx Cos[t]) Sin[b] + Cos[b] (n sy Sin[t])} /. bsparameters; sigmaplot[n_, color_] := ParametricPlot[c[t, n], {t, 0, 2 [Pi]}, PlotStyle -> {Thick, color, Dashed}];

central = ListContourPlot[dataf, PlotRange -> All /. bsparameters, ColorFunction -> "DeepSeaColors", PlotLegends -> Placed[BarLegend["DeepSeaColors", LegendLayout -> "Row", LegendMarkerSize -> 390], Below], ImageSize -> 377]; marginal1 = ListLinePlot[ Transpose[{Reverse@Map[#[[1, 2]] &, Transpose[data]], Map[Total@#[[All, 3]] &, Transpose[data]]}], Frame -> True, AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, Filling -> Bottom, ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}]; marginal2 = ListLinePlot[Map[{#[[1, 1]], Total@#[[All, 3]]} &, data], Frame -> True, AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, Filling -> Bottom, ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}]; final = Graphics[{Inset[ Show[{central, sigmaplot[1, Red](,Epilog[Rule]{Arrow[{c[0, 1],.93c[0,1]}],Text[Style[Subscript[[Sigma], 1],Red],.93c[0, 1]]})}, PlotRange -> All], {101.5, 20 + 150 + 85 + 10}, {Center, Center}, {150, 170}], Rotate[Inset[ marginal1, {100 + 24, 150 + 85 + 45}, {Left, Center}, {145, 50}], 3 [Pi]/2], Inset[marginal2, {101, 150 + 85 + 10 + 124}, {Center, Center}, {148, 40}]}, ImageSize -> 500]; Magnify[final, 1.5] ]

data = BinCounts[
   Select[RandomReal[
     NormalDistribution[0, 1], {10^5, 
      2}], -3 <= #[[1]] <= 3 && -3 <= #[[2]] <= 3 &], 0.1, 0.1];
data1 = Table[
   1.*a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[b])^2/(2 sy^2 + 
             RandomReal[{0, 1}])) - ((-mx + x) Cos[b] + (-my + y) Sin[
              b])^2/(2 sx^2 + RandomReal[{0, 1}])) /. {a -> 1, 
     my -> -1, mx -> -4, sx -> 2, sy -> 2, b -> 7 \[Pi]/3}, {x, -10, 
    10, 1}, {y, -10, 10, 1}];
Coolplot[data1_] := 
 Module[{data, dataf, sx0, sy0, mx0, my0, fm, bsparameters, sigmaplot,
    marginal1, marginal2, final, central, c},
  
  data = Table[{x, y, data1[[x, y]]}, {x, 1, Length@data1[[1]]}, {y, 
     1, Length@data1[[All, 1]]}];
  dataf = Flatten[data, 1];
  sx0 = Max[Map[StandardDeviation[#[[All, 3]]] &, data]];
  sy0 = Max[Map[StandardDeviation[#[[All, 3]]] &, Transpose[data]]];
  {mx0, my0} = 
   Extract[dataf, Position[dataf[[All, 3]], Max[dataf[[All, 3]]]]][[
    1, {1, 2}]];
  fm = Quiet@
    NonlinearModelFit[dataf, 
     a E^(-(((-my + y) Cos[b] - (-mx + x) Sin[
                 b])^2/(2 sy^2)) - ((-mx + x) Cos[b] + (-my + y) Sin[
               b])^2/(2 sx^2)), {{a, 0.1}, {b, 0}, {mx, mx0}, {my, 
       my0}, {sx, sx0}, {sy, sy0}}, {x, y}];
  bsparameters = fm["BestFitParameters"];
  c[t_, n_] := {mx + Cos[b] (n sx Cos[t]) - Sin[b] (n sy Sin[t]), 
     my + (n sx Cos[t]) Sin[b] + Cos[b] (n sy Sin[t])} /. bsparameters;
  sigmaplot[n_, color_] := 
   ParametricPlot[c[t, n], {t, 0, 2 \[Pi]}, 
    PlotStyle -> {Thick, color, Dashed}];
  
  
  
  central = 
   ListContourPlot[dataf, PlotRange -> All /. bsparameters, 
    ColorFunction -> "DeepSeaColors", 
    PlotLegends -> 
     Placed[BarLegend["DeepSeaColors", LegendLayout -> "Row", 
       LegendMarkerSize -> 390], Below], ImageSize -> 377];
  marginal1 = 
   ListLinePlot[
    Transpose[{Reverse@Map[#[[1, 2]] &, Transpose[data]], 
      Map[Total@#[[All, 3]] &, Transpose[data]]}], Frame -> True, 
    AspectRatio -> 1/4, PlotRange -> All, InterpolationOrder -> 0, 
    Filling -> Bottom, ColorFunction -> "DeepSeaColors", 
    FrameTicks -> {None, Automatic}];
  marginal2 = 
   ListLinePlot[Map[{#[[1, 1]], Total@#[[All, 3]]} &, data], 
    Frame -> True, AspectRatio -> 1/4, PlotRange -> All, 
    InterpolationOrder -> 0, Filling -> Bottom, 
    ColorFunction -> "DeepSeaColors", FrameTicks -> {None, Automatic}];
  final = 
   Graphics[{Inset[
      Show[{central, sigmaplot[1, Red](*,Epilog\[Rule]{Arrow[{c[0,
        1],.93c[0,1]}],Text[Style[Subscript[\[Sigma], 1],Red],.93c[0,
        1]]}*)}, PlotRange -> All], {101.5, 
       20 + 150 + 85 + 10}, {Center, Center}, {150, 170}], 
     Rotate[Inset[
       marginal1, {100 + 24, 150 + 85 + 45}, {Left, Center}, {145, 
        50}], 3 \[Pi]/2], 
     Inset[marginal2, {101, 150 + 85 + 10 + 124}, {Center, 
       Center}, {148, 40}]}, ImageSize -> 500];
  Magnify[final, 1.5]
  ]
Tweeted twitter.com/#!/StackMma/status/605200523780870145
edited tags
Link
Alexey Popkov
  • 62.3k
  • 7
  • 154
  • 375
Loading
added 331 characters in body
Source Link
Dargor
  • 1.4k
  • 9
  • 17
Loading
added 212 characters in body
Source Link
C. E.
  • 71.2k
  • 6
  • 141
  • 269
Loading
added 3358 characters in body
Source Link
Dargor
  • 1.4k
  • 9
  • 17
Loading
Source Link
Dargor
  • 1.4k
  • 9
  • 17
Loading