0
$\begingroup$

I have defined a custom gradient palette as follows:

ColorData[1];
new = {{"MyGradient", "", {}}, {"Gradients"}, 1, {0, 1}, {Darker[Blue], Blue, 
Cyan, Yellow, Orange, Red, Darker[Red]}, ""};
AppendTo[DataPaclets`ColorDataDump`colorSchemes,new];
AppendTo[DataPaclets`ColorDataDump`colorSchemeNames, new[[1, 1]]];

And using the following I have potted some data.

plot2 = ListDensityPlot["file.dat", ColorFunction -> 
(ColorData["MyGradient"][Rescale[#, {0, 0.025}]] &),
PlotRange -> {{-radi2D, radi2D}, {-radi2D, radi2D}, {0,1}},
Frame->True,FrameLabel -> {LabelXX, LabelYY},LabelStyle -> 26,
PlotLabel -> Style[Row@{"t=",Time," ps"},FontSize -> 26],
PlotLegends -> BarLegend[{"MyGradient",{0,0.025}},
ColorFunctionScaling -> True, LabelStyle -> {FontSize -> 26}, 
LegendMarkerSize -> {30,650}],
ColorFunctionScaling -> False,
ClippingStyle -> Yellow, AspectRatio -> 1, ImageSize -> 700];

Export[ToString[StringJoin[{"fotogramas.C_2D.",Time,".png"}]], plot2, "PNG"];

The problem is that I cannot get the legend bar filled with the cutom gradient as seen in the figure below.

enter image description here

Any ideas? Thank you!

$\endgroup$
  • $\begingroup$ PlotLegend->BarLegend[{{Darker[Blue], Blue, Cyan, Yellow, Orange, Red, Darker[Red]}, {0, 0.025}}] $\endgroup$ – Sumit Jul 19 '17 at 14:51
  • $\begingroup$ It worked perfectly and it was a simple solution! Many thanks! $\endgroup$ – Miquel Blancafort Jorquera Jul 19 '17 at 16:18
2
$\begingroup$
Legended[
 ListDensityPlot[
  Table[y + Sin[x^2 + y^2], {x, -4, 4, 0.2}, {y, -4, 4, 0.2}],
  DataRange -> {{-4, 4}, {-4, 4}},
  ColorFunctionScaling -> False,
  ColorFunction -> (ColorData["MyGradient"][Rescale[#, {-4, 4}]] &)],
 BarLegend[{ColorData["MyGradient"], {-4, 4}},
  LabelStyle -> {FontSize -> 26},
  LegendMarkerSize -> {30, 350}]]

enter image description here

$\endgroup$
  • $\begingroup$ I have been trying it and did not work... Maybe there is something wrong in my code... Thanks anyway! $\endgroup$ – Miquel Blancafort Jorquera Jul 19 '17 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.