I want to create a two-dimensional plot using data from an external file. This file contains several triplets of numbers. The first two columns indicate the x and y position, while the third one works as an indicator for every (x,y) point. The desired plot should depict each point as a colorful dot and the color of each dot should be assigned according to the value of the third column. I used ListDensityPlot
to create my plot but for a strange reason it joins all the points together and of course spreads the colors. This is the code I used:
SetDirectory[" ... To be inserted ... "];
data = Import["Esc_data.out", "Table"];
S1 = ListDensityPlot[data, Mesh -> None, ColorFunction -> "Rainbow",
PlotLegends -> Placed[BarLegend[Automatic, LegendMargins ->
{{0, 0}, {10, 5}}, LegendLabel -> "\!\(\*SubscriptBox[\(log\), \(10\)]\)(Tesc)",
LabelStyle -> {FontSize -> 15, FontFamily -> "Helvetica"}],
Right], PerformanceGoal -> "Quality", FrameLabel -> {"x", "y"},
RotateLabel -> False,
LabelStyle -> Directive[FontSize -> 17, FontFamily -> "Helvetica"],
ImageSize -> 500]
The correct plot should be the following:
It took me two minutes and four lines in gnuplot
to create this plot! So, it must be achievable in Mathematica too. However, I couldn't find out how to control the size of the dots and mainly how to "tell" to the program not to join the points between them.
The data file can be obtained here or here.
Many many thanks in advance!
I modified VLC's last version like this
Clear[colorbar]
colorbar[{min_, max_}, colorFunction_: Automatic, divs_: 150] :=
DensityPlot[y, {x, 0, 0.1}, {y, min, max}, AspectRatio -> 10,
PlotRangePadding -> 0, PlotPoints -> {2, divs}, MaxRecursion -> 0,
Frame -> True,
FrameLabel -> {{None,
"log10(\!\(\*SubscriptBox[\(T\), \(esc\)]\))"}, {None, None}},
LabelStyle -> Directive[FontFamily -> "Helvetica", 15],
FrameTicks -> {{None, All}, {None, None}},
FrameTicksStyle -> Directive[FontFamily -> "Helvetica", 15, Plain],
ColorFunction -> colorFunction]
With[{opts = {ImageSize -> {Automatic, 500}}, cf = "Rainbow"},
Row[{ListPlot[List /@ data[[All, {1, 2}]],
PlotStyle -> ({PointSize[0.0045], ColorData[cf][#1]} & /@
Rescale[data[[All, 2]], {1.5, 5}]),
PlotRange -> {{-1, 1}, {-1, 1}}, AspectRatio -> 1, Frame -> True,
AspectRatio -> 1, RotateLabel -> False, Axes -> None,
FrameTicks -> True, FrameLabel -> {"x", "y"},
LabelStyle -> Directive[FontFamily -> "Helvetica", 17],
ImagePadding -> {{60, 10}, {60, 20}}, opts],
Show[colorbar[{1.5, 5}, cf], ImagePadding -> {{10, 60}, {20, 10}},
opts]}]]
Now the frame labels of the main plot are shown. However, the colorbar is larger than the square. I want the height of the colorbar to be the same as the height of the square. Finally, how could I merge in a Show
this plot with the following contour
V = 1/2*(ω1^2*x^2 + ω2^2*y^2) - ϵ*x^2*y^2;
ω1 = 0.4; ω2 = 0.4;
ϵ = 1;
xmin = 1;
hesc = 0.0064;
C0 = ContourPlot[V, {x, -xmin, xmin}, {y, -xmin, xmin},
Contours -> {hesc}, ContourStyle -> {Gray, Thickness[0.003]},
AspectRatio -> 1, ContourShading -> False, PlotRange -> All,
PlotPoints -> 200, ImageSize -> 500];
ListDensityPlot
SHOULD have an option likeJoined->False
. $\endgroup$