66

50

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?**

You can check the seaborn page.

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.

Some example data for doing the plots:

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

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:

```
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}];
```

Defining the plotting function:

```
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]
]
```

To spawn the plot use:

```
Coolplot[data1]
```

2Since you've spent some time with this already you probably have Mathematica code for generating the data to create those contour plots, please include that and anything else that may help people get started. Maybe you also have some observations about the colors schemes for example. – C. E. – 2015-05-31T23:45:03.600

@Pickett Thank you for your comment!! I have edited the question to add a starter piece of code to the second plot. I am very null at colors so i am so sorry but i feel that i cannot help so much in this aspect. – Dargor – 2015-06-01T00:00:44.320

2

Two closely related posts (only regarding the color vs. lightness issue): Is there an easy way to use Matteo Niccoli's perceptual color maps for 2D plots in Mathematica? and Create colour with given lightness value.

– Jens – 2015-06-01T04:11:33.147As you can see from the excellent answers, the issue here isn't really where you

can, but whether it's worth the effort. The Python language, APIs, and packages are designed for (and continuously actively improved by)actual users, making whatever compromises and adjustments are effective in creating a powerful, easy to use and understand tool for actual use cases.Mathematicahas a diametrically opposite design philosophy: it is a monolithic system that adheres to a very small set of rules. – orome – 2015-06-04T12:10:57.607This is great for some things (it lets just about anything on Earth be built in a consistent fashion and subsequently treated as an expression that can be analyzed, decomposed, etc.); but is not much help in a wide variety of actual use cases. – orome – 2015-06-04T12:12:02.140

1@raxacoricofallapatorius That's correct. But i also find important to reduce your workflow scope to the minimum possible. And if you are confortable with a certain language, that's important too. At the end of the day knowing a lot of languages and possibilities is really good, but people like working with the tools they like....think for example in debugging a complicate plotting program in a language that you do not feel confortable. – Dargor – 2015-06-04T14:56:10.923