2
$\begingroup$

I am trying to beautify a contour plot where I have a wide data range. But still I want to use a linear scale for axis. But due to large range of the data, the most of the contours are restricted to a very small region. This is the reason I want to set custom contours.

The problem is, I like the color shading progression without the custom contours. As soon as I introduce custom contours this is gone. Somehow I would still like to bring the same shading back for custom contours. How should I do that?

Here is an example (but not with real data though but good enough to show)

 data = {{0.6994*10^-03, 0.1641*10^-02, 0.5393*10^-02, 0.1160*10^-01, 
0.2020*10^-01, 0.3113*10^-01, 0.6798*10^-01, 0.1170, 0.1760, 
0.2426, 0.3144, 0.3889, 0.4640, 0.5378, 0.6088, 0.6758, 0.7380, 
0.7948, 0.8460, 0.8915, 0.9315, 0.9661, 0.9957, 
1.021}, {0.3128*10^-03, 0.6929*10^-03, 0.2208*10^-02, 
0.4717*10^-02, 0.8199*10^-02, 0.1263*10^-01, 0.2758*10^-01, 
0.4752*10^-01, 0.7157*10^-01, 0.9877*10^-01, 0.1281, 0.1586, 
0.1894, 0.2198, 0.2490, 0.2766, 0.3022, 0.3256, 0.3467, 0.3655, 
0.3821, 0.3964, 0.4087, 0.4190}, {0.1544*10^-03, 0.3243*10^-03, 
0.1002*10^-02, 0.2125*10^-02, 0.3685*10^-02, 0.5670*10^-02, 
0.1239*10^-01, 0.2135*10^-01, 0.3219*10^-01, 0.4446*10^-01, 
0.5772*10^-01, 0.7153*10^-01, 0.8550*10^-01, 0.9926*10^-01, 
0.1125, 0.1251, 0.1368, 0.1475, 0.1572, 0.1659, 0.1735, 0.1801, 
0.1858, 0.1906}, {0.8212*10^-04, 0.1642*10^-03, 0.4920*10^-03, 
0.1035*10^-02, 0.1791*10^-02, 0.2752*10^-02, 0.6009*10^-02, 
0.1036*10^-01, 0.1563*10^-01, 0.2161*10^-01, 0.2808*10^-01, 
0.3483*10^-01, 0.4167*10^-01, 0.4842*10^-01, 0.5494*10^-01, 
0.6113*10^-01, 0.6691*10^-01, 0.7221*10^-01, 0.7702*10^-01, 
0.8133*10^-01, 0.8513*10^-01, 0.8846*10^-01, 0.9134*10^-01, 
0.9379*10^-01}, {0.4630*10^-04, 0.8852*10^-04, 0.2571*10^-03, 
0.5367*10^-03, 0.9255*10^-03, 0.1421*10^-02, 0.3099*10^-02, 
0.5346*10^-02, 0.8070*10^-02, 0.1116*10^-01, 0.1452*10^-01, 
0.1802*10^-01, 0.2158*10^-01, 0.2510*10^-01, 0.2851*10^-01, 
0.3175*10^-01, 0.3478*10^-01, 0.3758*10^-01, 0.4012*10^-01, 
0.4240*10^-01, 0.4443*10^-01, 0.4622*10^-01, 0.4777*10^-01, 
0.4910*10^-01}, {0.2735*10^-04, 0.5016*10^-04, 0.1413*10^-03, 
0.2925*10^-03, 0.5028*10^-03, 0.7708*10^-03, 0.1680*10^-02, 
0.2899*10^-02, 0.4377*10^-02, 0.6060*10^-02, 0.7886*10^-02, 
0.9799*10^-02, 0.1174*10^-01, 0.1367*10^-01, 0.1554*10^-01, 
0.1733*10^-01, 0.1900*10^-01, 0.2055*10^-01, 0.2197*10^-01, 
0.2324*10^-01, 0.2438*10^-01, 0.2539*10^-01, 0.2627*10^-01, 
0.2703*10^-01}, {0.4068*10^-06, 0.5607*10^-06, 0.1176*10^-05, 
0.2201*10^-05, 0.3630*10^-05, 0.5458*10^-05, 0.1170*10^-04, 
0.2018*10^-04, 0.3061*10^-04, 0.4267*10^-04, 0.5603*10^-04, 
0.7033*10^-04, 0.8522*10^-04, 0.1004*10^-03, 0.1156*10^-03, 
0.1305*10^-03, 0.1451*10^-03, 0.1591*10^-03, 0.1724*10^-03, 
0.1850*10^-03, 0.1969*10^-03, 0.2080*10^-03, 0.2182*10^-03, 
0.2277*10^-03}, {0.2229*10^-06, 0.2981*10^-06, 0.5990*10^-06, 
0.1101*10^-05, 0.1800*10^-05, 0.2695*10^-05, 0.5758*10^-05, 
0.9923*10^-05, 0.1506*10^-04, 0.2103*10^-04, 0.2766*10^-04, 
0.3479*10^-04, 0.4225*10^-04, 0.4988*10^-04, 0.5757*10^-04, 
0.6519*10^-04, 0.7264*10^-04, 0.7985*10^-04, 0.8677*10^-04, 
0.9336*10^-04, 0.9959*10^-04, 0.1055*10^-03, 0.1109*10^-03, 
0.1161*10^-03}};

With this data I am plotting as below:

  ListContourPlot[
  data,
  PlotRange -> All,
  Contours -> 5,
  ColorFunction -> ColorData[{"BlueGreenYellow", "Reverse"}],
  PlotLegends -> BarLegend[Automatic]
  ]

Since the plot is concentrated mostly in a small region I want to use some custom contours instead, like:

             zValues = {0.001, 0.01, 0.1, 0.5, 0.8};

   ListContourPlot[
   data,
   PlotRange -> All,
   Contours -> zValues,
   ColorFunction -> ColorData[{"BlueGreenYellow", "Reverse"}],
   PlotLegends -> BarLegend[Automatic]
   ]

I want to set Contours->zValues but want to same color progression like Contours->5

$\endgroup$

1 Answer 1

2
$\begingroup$

You can extract the five colors from the first plot and use them as the option value for ContourShading:

lcp = ListContourPlot[data, 
   ImageSize -> Medium,
   PlotRange -> All, 
   Contours -> 5, 
   ColorFunction -> ColorData[{"BlueGreenYellow", "Reverse"}], 
   PlotLegends -> BarLegend[Automatic]];

colorlist = Cases[lcp[[1]], {___, clr_RGBColor, _GraphicsGroup} :> clr, All]

enter image description here

zValues = {0.001, 0.01, 0.1, 0.5, 0.8};

lcp2 = ListContourPlot[data, 
  ImageSize -> Medium,
  PlotRange -> All, 
  Contours -> zValues, 
  ContourShading -> colorlist, 
  PlotLegends -> BarLegend[Automatic]];

Row[{lcp, lcp2}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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