Data visualization with SAS programming

SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

Accepted Solution Solved
Reply
Contributor tc
Contributor
Posts: 74
Accepted Solution

SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

In the code below, which inserts a photo into a 40"x22" image (for an SGF e-poster), what does the 75 in "width=75" refer to?
____________

 

function="Image"; * Image annotation parameters;
image="/folders/myfolders/SGF2017Photos/VenetianLobby.jpg"; anchor="bottomleft";
imagescale='fitwidth'; layer='back'; border='true '; linethickness=10; linecolor="black";
drawspace="datavalue"; x1="18APR2016:19:45:00"dt; y1=7000; width=75; widthunit='pixel';
output;

...

...

ods listing image_dpi=96 gpath='/folders/myfolders' device=png;
ods graphics on / reset antialias width=40in height=22in imagename="SGF2017steps1" imagefmt=png antialias;
____________

 

I've got this working by trial-and-error, but can't for the life of me figure out what the "width=75" refers to - it doesn't seem to correspond to x-axis units, percent of image, or pixels, but that's probably just my lack of understanding (I'll have to ask my web designer daughter to give me an Images-for-Dummies lesson!).

 

If I open the generated .png file in Paintbrush, the image is 3840 x 2112 px, which is what I'd expect (40in x 96dpi = 3840px), but the left side of the image starts at about 857px and ends at 1204px (including border), or 872px and 1188px (excluding border). If my math's correct, the latter 316px or 316/3840=8.23% of the image. In x-axis units, the picture (without border) starts at "18APR2016:19:45:00"dt and ends at "19APR2016:02:00:00"dt (difference=22500).

 

So, any insight on how "width=75" relates to this? If this was SAS Jeopardy, this would be my $1,000 question for ODS Graphics. :-)

 

Thanks - appreciate the help!


Accepted Solutions
Solution
‎03-03-2017 02:36 PM
SAS Super FREQ
Posts: 1,078

Re: SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

Hi tc,

 

You have found a bug.  We are looking into it.  But, basically the image size is being scaled by a factor related to graph size specified to the "Design size" which is usually 640x480.  This happens even when we set NOSCALE on the ODS Graphics statement.  We are still digging and should have an answer.

 

If you want to place an image behind the graph in the data area, I suggest DrawSpace=WallPercent.  Then placing it at (0, 0) with anchor of bottom right you will reliably get the image to fit the wall area regardless of the dpi or graph size.

 

data anno;
length function $10;
function="Image";
image="C:\Work\SASUser\Communities\Pgm\tc.png";
anchor="bottomleft";
layer='back';
drawspace="wallpercent";
x1=0;
y1=0;
width=100;
height=100;
output;
run;

 

ods _all_ close; run;
ods listing image_dpi=200 gpath='C:\Work\SASUser\Communities\Image' device=png;
ods graphics on / reset width=4in height=3in antialias imagename="TEST4x3" imagefmt=png antialias;
proc sgplot data=sashelp.cars(obs=2) sganno=anno nowall;
scatter x=mpg_city y=mpg_highway;
xaxis min=0;
yaxis min=0;
run;
ods _all_ close; run;

View solution in original post


All Replies
Super Contributor
Posts: 283

Re: SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

The documentation says that width is "specifies the width of the annotation. Specify a positive number greater than zero. You can use the WIDTHUNIT variable to specify the unit of measurement." That seems straightforward and I'm sure you've looked at that as well, so my question is what happens to the resulting graph when you change value from 75 to, say, 100? Or 50? Does it not affect the annotation? What if you omit it altogether? I would think its effect as you alter its value in the code would give you some indication of what it's doing, no?

SAS Super FREQ
Posts: 1,078

Re: SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

I would expect the width is 75 pixels (as indicated by the WidthUnit parameter).  It will be scaled by DPI, but I still would not expect 316 px.  Please attach resulting image, or preferably the code we can run to investigate.

Contributor tc
Contributor
Posts: 74

Re: SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

[ Edited ]

Here's some simpler code with two tests that illustrate my probably-due-to-a-lack-of-understanding-of-images-and/or-Paintbrush confusion. Smiley Happy

 

* CREATE ANNOTATON DATA SET - PICTURE TO BE INSERTED IS 200x100 .png;

data anno;                                           
function="Image";                                
image="/folders/myfolders/200x100.png"; 
anchor="bottomleft"; 
imagescale='fitwidth'; 
layer='back'; 
drawspace="datavalue"; 
x1=0; 
y1=0;
width=350; 
widthunit='pixel';
output;

* TEST 1: MAKE PICTURE A WIDTH OF 350 ON A 40x22in IMAGE;

ods _all_ close; run;                                
ods listing image_dpi=96 gpath='/folders/myfolders' device=png;
ods graphics on / reset antialias width=40in height=22in imagename="TEST40BY22" imagefmt=png antialias;
proc sgplot data=sashelp.cars sganno=anno nowall;    
scatter x=mpg_city y=mpg_highway;
run;
ods _all_ close; run;                                 

* TEST 2: MAKE PICTURE A WIDTH OF 350 ON A 4x4in IMAGE;

ods _all_ close;                                  
ods listing image_dpi=96 gpath='/folders/myfolders' device=png;
ods graphics on / reset antialias width=4in height=4in imagename="TEST4BY4" imagefmt=png antialias;
proc sgplot data=sashelp.cars sganno=anno nowall;    
scatter x=mpg_city y=mpg_highway;  
run;
ods _all_ close; run;

 

And here is input picture  "/folders/myfolders/200x100.png".

 

200x100.png

 

Which looks like this in Paintbrush.

 

Paint200x100Screenshot.gif

 

This is what output file TEST40BY22.png looks like in Paintbrush.

 

Paint40x22Screenshot.gif

 

And, finally, here's what output file TEST4BY4.png looks like in Paintbrush.

 

PAINT4x4Screenshot.gif

 

I thought that the width=350 inserted picture would look the same - i.e., 350px - in both the larger and smaller output images since widthunit='pixel' was specified, but that's not the case.

 

Can you please comment on what I'm missing (be kind!)?

 

Thanks!

 

tc

 

p.s. In case it comes into play, my laptop resolution is 1366 x 768.

 

 

Solution
‎03-03-2017 02:36 PM
SAS Super FREQ
Posts: 1,078

Re: SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

Hi tc,

 

You have found a bug.  We are looking into it.  But, basically the image size is being scaled by a factor related to graph size specified to the "Design size" which is usually 640x480.  This happens even when we set NOSCALE on the ODS Graphics statement.  We are still digging and should have an answer.

 

If you want to place an image behind the graph in the data area, I suggest DrawSpace=WallPercent.  Then placing it at (0, 0) with anchor of bottom right you will reliably get the image to fit the wall area regardless of the dpi or graph size.

 

data anno;
length function $10;
function="Image";
image="C:\Work\SASUser\Communities\Pgm\tc.png";
anchor="bottomleft";
layer='back';
drawspace="wallpercent";
x1=0;
y1=0;
width=100;
height=100;
output;
run;

 

ods _all_ close; run;
ods listing image_dpi=200 gpath='C:\Work\SASUser\Communities\Image' device=png;
ods graphics on / reset width=4in height=3in antialias imagename="TEST4x3" imagefmt=png antialias;
proc sgplot data=sashelp.cars(obs=2) sganno=anno nowall;
scatter x=mpg_city y=mpg_highway;
xaxis min=0;
yaxis min=0;
run;
ods _all_ close; run;

Contributor tc
Contributor
Posts: 74

Re: SAS ODS Graphics for $1,000, Alex: Width Parameter in ODS Graphics Image Annotation?

Sounds good. Since I'm creating a fixed-size image (poster), and know what size I want the inserted photos to be, I actually considered going with a percentage earlier. Simple enough to change now, even if I was too stubborn to do so earlier. Thanks!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 182 views
  • 3 likes
  • 3 in conversation