<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use my colors &amp;quot;as is&amp;quot; in a filled contour plot in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/658216#M20059</link>
    <description>&lt;P&gt;Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;. I think your example works because you used nlevels to create 8 evenly spaced levels. However, in your code, if you replace nlevels=8 with&amp;nbsp;levels=(0 0.3 1 1.3 2 2.5 3 3.75) to create 8 irregularly spaced levels, then the resulting figure no longer uses the colors you chose. In my real use case, I do want to pick my own level values and they are not evenly spaced, so unfortunately your suggestion doesn't work for me. (For context, I'm plotting hazard ratios as a function of two predictor variables. I'm using the levels to bin the HRs into meaningful ranges and they are not evenly spaced.)&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jun 2020 21:09:52 GMT</pubDate>
    <dc:creator>dagremu</dc:creator>
    <dc:date>2020-06-12T21:09:52Z</dc:date>
    <item>
      <title>Use my colors "as is" in a filled contour plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/657704#M20038</link>
      <description>&lt;P&gt;I'm creating a filled contour plot, using contourplotparm in GTL, and I want to precisely control the color for each filled-in area. SAS, however, takes my color choices only as an input in some algorithm to determine the colors it actually uses.&amp;nbsp;Here's an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* GTL template for a filled contour plot, with 5 colors. The contour levels must
  be specified when calling SGRENDER.;
proc template;
define statgraph ContourPlotParm;
dynamic _levels _title;
begingraph;
	entrytitle _title;
	layout overlay;
		contourplotparm x=Height y=Weight z=Density /
			contourtype=fill
			levels=_levels
			colormodel=(red yellow green blue purple)
			name="Contour";
		continuouslegend "Contour";
	endlayout;
endgraph;
end;
run;

* render a contour plot with 6 contour levels, and thus with 5 filled-in areas
  between the levels;
ods graphics / width=3in;
proc sgrender data=sashelp.gridded template=ContourPlotParm;
	dynamic _levels='0 0.0003 0.0007 0.001 0.0014 0.0017' _title='Figure 1';
run;

* same as above, but different contour levels;
proc sgrender data=sashelp.gridded template=ContourPlotParm;
	dynamic _levels='0 0.0005 0.0007 0.001 0.0014 0.0017' _title='Figure 2';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here's the two resulting figures:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Contour plot examples.png" style="width: 575px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/42730i6342C560A8A45F4C/image-size/large?v=v2&amp;amp;px=999" role="button" title="Contour plot examples.png" alt="Contour plot examples.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;First, note that neither figure uses exactly the colors I wanted: there's no red, there's no yellow, and I'm guessing that the other colors aren't exactly what I specified. Second, note that the two figures have different colors from each other even though I did not change the colors that I specified; the only difference is the contour level values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is, how do I get exactly the colors I want? I think another way of asking this is, given the contour levels and the colors that I want, is it possible to come up with a different set of colors such that, when I specify these colors in the colormodel option, SAS ends up actually using the colors I want?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SAS documentation for contourplotparm offers the following hint, but I'm not sure what to make of it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV class="xisDoc-argDescriptionPair"&gt;&lt;DIV class="xisDoc-argumentDescription"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;For a contour plot of type FILL, LINEFILL, or LABELEDLINEFILL, the color that is chosen for the first segment is the color for the N+1 inflection point and not the starting color in the color model.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="xisDoc-argDescriptionPair"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 23:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/657704#M20038</guid>
      <dc:creator>dagremu</dc:creator>
      <dc:date>2020-06-11T23:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use my colors "as is" in a filled contour plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/658178#M20058</link>
      <description>&lt;P&gt;Try using the&lt;/P&gt;
&lt;P&gt;&lt;A tabindex="0" href="https://go.documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.2&amp;amp;docsetId=grstatgraph&amp;amp;docsetTarget=n08rjwb09dl44cn1nqbhg4bt4k6f.htm&amp;amp;locale=en#n0dnwmkitrz4r1n0zlej13we8ywg" data-docset-version="9.4" data-docset-id="grstatgraph" data-original-href="#n0dnwmkitrz4r1n0zlej13we8ywg"&gt;LEVELS=(&lt;EM class="xisDoc-userSuppliedValue"&gt;contour-value-list&lt;/EM&gt;)&lt;/A&gt;&amp;nbsp;or NLEVELS= option to make sure that the number of areas matches the number of colors in the color ramp. Here is an example that seems to work, but I had to add a fake color (WHITE) at the lower end of the color ramp to get it to work. Not sure why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc template;
define statgraph ContourPlotParm2;
dynamic _X _Y _Z _TITLE;
begingraph;
   entrytitle _TITLE;
   layout overlay;
      contourplotparm x=_X y=_Y z=_Z /
        contourtype=fill nlevels=8  
        colormodel=(white red orange yellow green blue magenta grey) name="Contour";
      continuouslegend "Contour" / title=_Z;
   endlayout;
endgraph;
end;
run;

data Have;
do y=-5 to 5 by 0.1;
   do x=-5 to 5 by 0.1;
      z = x*x/20 + y*y/10;
      output;
   end;
end;
run;
proc means data=Have;run;

proc sgrender data=Have template=ContourPlotParm2;
dynamic _TITLE="Contour Plot"
        _X="x" _Y="y" _Z="z";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Jun 2020 18:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/658178#M20058</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-06-12T18:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use my colors "as is" in a filled contour plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/658216#M20059</link>
      <description>&lt;P&gt;Thanks, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;. I think your example works because you used nlevels to create 8 evenly spaced levels. However, in your code, if you replace nlevels=8 with&amp;nbsp;levels=(0 0.3 1 1.3 2 2.5 3 3.75) to create 8 irregularly spaced levels, then the resulting figure no longer uses the colors you chose. In my real use case, I do want to pick my own level values and they are not evenly spaced, so unfortunately your suggestion doesn't work for me. (For context, I'm plotting hazard ratios as a function of two predictor variables. I'm using the levels to bin the HRs into meaningful ranges and they are not evenly spaced.)&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 21:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/658216#M20059</guid>
      <dc:creator>dagremu</dc:creator>
      <dc:date>2020-06-12T21:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Use my colors "as is" in a filled contour plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/658223#M20062</link>
      <description>&lt;P&gt;I suspect part of the issue revolves around your "levels", 6 boundaryies=&amp;gt;7 groups to display, not aligning with colors, 5, forcing an added interpolation somewhere. Probably compounded by the last group, at least with the level choices you show has very few records compared to the last level.&lt;/P&gt;
&lt;P&gt;I can get this to use the 5 colors PLUS one, this way. But since it requires a data step to force your increments onto the density value I suspect it isn't as nice as you hoped.&lt;/P&gt;
&lt;PRE&gt;proc template;
define statgraph ContourPlotParm;
dynamic _levels _title;
begingraph;
	entrytitle _title;
	layout overlay;
		contourplotparm x=Height y=Weight z=Density /
			contourtype=fill
			levels=_levels
			colormodel=(white red yellow green blue purple)
			name="Contour";
		continuouslegend "Contour";
	endlayout;
endgraph;
end;
run;
data toplot;
   set sashelp.gridded;
   array _l(6) _temporary_( 0,0.0003,0.0007,0.001,0.0014,0.0017);
   array _z(6);
   do i= 1 to dim(_l);
      _z[i]= abs(_l[i] - density);
   end;
   tl= whichn(min(of _z(*)),of _z(*));
   density=_l[tl];
run;


proc sgrender data=toplot template=ContourPlotParm;
	dynamic _levels='0 0.0003 0.0007 0.001 0.0014 0.0017' 
         _title='Figure 1'
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;This code&lt;/P&gt;
&lt;PRE&gt;proc format;
value density
0              ='     0'
0     &amp;lt;- 0.0003='     0&amp;lt;- 0.0003'
0.0003&amp;lt;- 0.0007='0.0003&amp;lt;- 0.0007'
0.0007&amp;lt;- 0.001 ='0.0007&amp;lt;- 0.001'
0.001 &amp;lt;- 0.0014='0.001 &amp;lt;- 0.0014'
0.0014&amp;lt;- 0.0017='0.0014&amp;lt;- 0.0017'
0.0017&amp;lt;- high  ='0.0017+'
;
run;

ods listing;
proc freq data=sashelp.gridded;
   tables density;
   format density density.;
run;
ods listing close;&lt;/PRE&gt;
&lt;P&gt;Shows the groups with your boundary values:&lt;/P&gt;
&lt;PRE&gt;                       Density    Frequency     Percent     Frequency      Percent
              ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ
                   0                   138        3.83           138         3.83
                   0&amp;lt;- 0.0003         2858       79.39          2996        83.22
              0.0003&amp;lt;- 0.0007          284        7.89          3280        91.11
              0.0007&amp;lt;- 0.001           124        3.44          3404        94.56
              0.001 &amp;lt;- 0.0014          128        3.56          3532        98.11
              0.0014&amp;lt;- 0.0017           61        1.69          3593        99.81
              0.0017+                    7        0.19          3600       100.00

&lt;/PRE&gt;
&lt;P&gt;I am thinking of the old GMAPS Levels option where the interpolation was sometimes other than desired.&lt;/P&gt;
&lt;P&gt;Anyway that lead me to trying the starting data set with the format.&lt;/P&gt;
&lt;PRE&gt;proc sgrender data=sashelp.gridded template=ContourPlotParm;
	dynamic _levels='0 0.0003 0.0007 0.001 0.0014 0.0017' 
         _title='Figure 1'
   ;
   format density density.;
run;&lt;/PRE&gt;
&lt;P&gt;Which works, as I think you intended IF there are (at least?) 6 colors in the colorlist as in my version above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you may have to create a format for each different level list. And if you go to 8 levels I would expect this to break again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 22:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/658223#M20062</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-12T22:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Use my colors "as is" in a filled contour plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/661829#M20091</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. I think your code *appears* to work at first glance, but that's because the level values (0 0.0003 0.0007 0.001 0.0014 0.0017) are close-to-but-not-quite evenly spaced. If you inspect the color that should be pure red (i.e., cxFF0000) in the figure, it's actually cxFC282E; the other colors are all slightly off too. If you change the levels to&amp;nbsp;(0 0.0005 0.0007 0.001 0.0014 0.0017) so that they are less evenly spaced, then it becomes more obvious that your code has the same shortcomings as mine.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 15:56:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/661829#M20091</guid>
      <dc:creator>dagremu</dc:creator>
      <dc:date>2020-06-17T15:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use my colors "as is" in a filled contour plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/661832#M20092</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/186841"&gt;@dagremu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;. I think your code *appears* to work at first glance, but that's because the level values (0 0.0003 0.0007 0.001 0.0014 0.0017) are close-to-but-not-quite evenly spaced. If you inspect the color that should be pure red (i.e., cxFF0000) in the figure, it's actually cxFC282E; the other colors are all slightly off too. If you change the levels to&amp;nbsp;(0 0.0005 0.0007 0.001 0.0014 0.0017) so that they are less evenly spaced, then it becomes more obvious that your code has the same shortcomings as mine.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;When the requirement is "red" and the error is within monitor display size/ gamma/ brightness or other color correction settings affect I call that close enough. If the object is paper print and Pantone type settings that's past my non-paid grade.&lt;/P&gt;
&lt;P&gt;I don't use contour plots so have never had to try to force appearance, especially with uneven range values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 16:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/661832#M20092</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-17T16:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Use my colors "as is" in a filled contour plot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/661848#M20094</link>
      <description>&lt;P&gt;I agree,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;, and I didn't mean to seem nitpicky about tiny differences in color. In my real use case, the levels are unevenly spaced, and so the differences in color (between what I specify and what SAS uses) are more pronounced.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 17:18:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Use-my-colors-quot-as-is-quot-in-a-filled-contour-plot/m-p/661848#M20094</guid>
      <dc:creator>dagremu</dc:creator>
      <dc:date>2020-06-17T17:18:37Z</dc:date>
    </item>
  </channel>
</rss>

