[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: scaling issues with saved plots
From: |
George Barrick |
Subject: |
Re: scaling issues with saved plots |
Date: |
Mon, 11 Jun 2012 10:47:23 -0400 |
%% Subj: Re: scaling issues with saved plots
%%
%% 2012.06.10.14:35:52 UT
%%
%% Hi Ron (and others),
%%
%% Following is my response to Bob's (yech) suggestion:
%% "play with the axis scaling until it looks right instead of using
%% axis square".
%%
%% I must concede that these techniques are ones that (mostly)
%% only a mathematician can love, but they get the job done. I've
%% developed this approach beginning with some years doing Matlab
%% plots, followed by some more years adapting myself to the
%% GNU Octave plotting environment that uses Gnuplot. This slavish
%% attention to detail gets me a plot that is scaled precisely as
%% I want it. When I present stuff to students, they typically
%% grab for _any_ excuse to misunderstand what I say, and so my plots
%% need to be impeccably correct.
%%
%% Please freely take what you need, and discard the rest. I believe
%% that, because my discussions are already commented-out, you can just
%% save this message as a .m file, and then run it in the GNU Octave
%% interpreter to get a nice _circular_ circle. My name for this file
%% has been egcrcle.m.
%%
%% George g_barrick_at_walsh_dot_edu
%%
%********D%********D%********D%********D%********D%********D%********D%***f**
%%
%% Set up graphing parameters.
%% Set vectors which state window position and size. Keep in mind that
%% none of these settings is actually active when I declare them. The
%% settings become the ones used by GNU Octave only when I use them in
%% calls to the graphics functions figure() and axes().
%% NOTE: Most situations that I work with (UNIX, Linux and CygWin-X) take
%% the following dimensions to be hundredths of an inch on 8.5"x11" paper.
%%
%% Main plot
winXst = 288 ;
winYst = 320 ;
winWdt = 576 ;
winHgt = 416 ;
winPos = [ winXst winYst winWdt winHgt ] ;
%% All locations are stated relative to the window position, and so I
%% will use window width and height as denominators.
win = [ winWdt winHgt winWdt winHgt ] ;
%********D%********D%********D%********D%********D%********D%********D%***f**
%% Set the vector which gives area inside the window where axes will be
%% drawn.
plotWdt = 500 ;
plotHgt = 375 ;
plotXst = 36 ;
plotYst = 25 ;
plotPos = [ plotXst plotYst plotWdt plotHgt ] ./ win ;
%% Set limits for the axes.
xlims = [ -2.500, 2.500 ] ;
ylims = [ -1.750, 1.750 ] ;
%********D%********D%********D%********D%********D%********D%********D%***f**
%% The graphics functions figure() and axes() are called using the settings
%% I have written up. I use "hdle" or "mdle" as the graphics handle for
%% the figure window.
mdle = figure() ;
set( mdle,"position",winPos ) ;
%% Spawn axes first, then re-configure them.
qdle = axes() ;
set( qdle,"position",plotPos ) ;
set( qdle,"xlim",xlims,"ylim",ylims ) ;
%% Create the axis box, tics and labels.
%% The DataAspectRatio setting now seems to working as it should
%% in GNU Octave 3.4.2 and 3.6.2. This setting is required in
%% order to get a plot that is scaled as per the window settings
%% that I have declared previous to this line. Also, the
%% description in the GNU Octave 3.4.2 manual is a bit inaccurate.
%% The manual indicates that the property value should be a
%% two-vector, but the octave interpreter always squawks, and
%% insists that I provide a three-vector for this value.
set( qdle,"dataaspectratio",[ 1, 1, 1 ] ) ;
set( qdle,"nextplot","add","visible","on" ) ;
set( qdle, "xtick", [ -1.5, 0.0, 1.5 ] ) ;
set( qdle, "xticklabel", "-1.5|0.0|1.5" ) ;
set( qdle, "ytick", [ -1.5, 0.0, 1.5 ] ) ;
set( qdle, "yticklabel", "-1.5|0.0|1.5" ) ;
%% Create the graph.
%% Basic parameter required to create the plot.
%% A circle having this radius is the goal of this
%% plotting routine.
rval = 1.250 ;
%% Print a text label for the value or r.
strng = [ "r = ", sprintf("%6.3f\n", rval ) ] ;
posn = [ 1.020, -0.840 ] ;
hu = text(posn(1),posn(2),strng,"fontsize",16 );
%% difference between entries of t-value array
delta = rval / 40.0 ;
%% Array of t-values used to generate x-values and
%% y-values.
tvals = [ -1.0*rval : delta : 3.0*rval ] ;
%% Auxilliary arrays of values (same length as tvals) that
%% constitute fragments of expressions that define the
%% x-array and the y-array. Note that I'm using a slightly
%% wierd parametrization for this circle due to the fact
%% that it is an example intended to teach students about
%% parametrized curves:
%%
%% x = r - abs( t - r )
%%
%% y = sgn( t - r ) *
%% sqrt( abs( t -r ) * ( 2*r - abs( t - r ) ) )
%%
tones = ones( size( tvals ) ) ;
rones = rval * tones ;
avals = abs( tvals - rones ) ;
xvals = rones - avals ;
sgnms = sign( tvals - rones ) ;
yvals = sgnms .* sqrt( avals .* ( 2.0*rones - avals ) ) ;
%% Actually generate the plot on the axes.
n1 = plot( xvals, yvals, "k-" );
set(n1,"linewidth",2) ;
%% Create array of handles. Most folks feel that this is
%% a useless exercise in programmer's bookkeeping.
hndle = [ mdle; qdle; hu; n1 ] ;
%% standard printing size is -r150. NO! Standard printing size
%% is _not_ (any longer) -r150. It is -r72. The -r72 comes
%% close to scaling that I gave to original figure().
%% print -dsvg egcrcle.svg;
%% print(mdle,"egcrcle.png","-dpng","-S576,416");
%% print(mdle,"egcrcle.svg","-dsvg","-S576,416");
- Re: scaling issues with saved plots,
George Barrick <=