Axis control with PlotXY()

While I like the new GAUSS graphics, I'm having trouble controling the plot axes.

For example, I'm plotting some economic data from the 1960s to the present, so my x-vector for plotxy() is just something like seqa(1966,0.25,rows(Y)).

When my Y data is strictly positive, that works fine.

However, when my Y data contain both positive and negative values, plotxy insists on starting the x-axis at year 0, which scrunches all my data into a blur at the extreme right of the graph.

Surely there's a simple way to avoid this.....but I can't find it.

 

Any suggestions?

3 Answers



1



I tried this program below and a few combinations (more curves, only one negative element, without using a plotcontrol struct) on Windows 7 and Linux with GAUSS 13.0.3. In all cases the x axis ranged from the minimum x value to the maximum x value.

struct plotControl myPlot;
myPlot = plotGetDefaults("xy");

x = seqa(1960, 0.25, 53*4);
y = cos(seqa(0.1, 0.1, rows(x)));
plotxy(myPlot, x,y);

Does this display correctly for you? Could you save your x and y variables as .fmt files with the save command and send them to support.



1



This is a problem related to all of the columns being passed into plotXY that have only missing values. This has already been fixed in version 13.1 which will be released in January 2013.

As a workaround here is a procedure to remove all rows that only contain missing values.

new;
struct plotControl myPlot;
myplot = plotGetDefaults("xy");
load rawdataF;
PlotSetLegend(&myplot,"off");
x = seqa(2009-0.25*cols(rawdataF),.25,cols(rawdataF));
plotXY(myPlot, x, delMissRows(rawdataF)');


proc delMissRows(x);
	local mask, idx, xout, rtrim, xctr;
	
	//Which rows have as many missings as columns
	mask = sumr(x .== miss(0,0));
	
	//Preallocate output matrix
	rtrim = sumc(mask .== cols(x));
	xout = zeros(rows(x) - rtrim, cols(x));
	
	//Fill in xout
	xctr = 1;
	for i(1, rows(x), 1);
		if mask[i] != cols(x);
			xout[xctr, .] = x[i,.];
			xctr = xctr + 1;
		endif;
	endfor;
	
	retp(xout);	
endp;

aptech

1,773


0



Hi Jason.

Thanks for your answer. Your example displays perfectly for me.

I've tried to create a single example that reproduces the problem, using my original data saved in .fmt format as you suggested. (I can't figure out how to attach the .fmt file to this forum post, so I'll send that separately by e-mail.) Here's a program that should reproduce the problem.

new;
struct plotControl myPlot;
myplot = plotGetDefaults("xy");
load rawdataF;
PlotSetLegend(&myplot,"off");
plotxy(myplot,seqa(2009-0.25*cols(rawdataF),.25,cols(rawdataF)),rawdataF');

This gives me a plot whose horizontal axis starts at 0, despite the fact that rawdataF is a 157x170 matrix.

 

Thanks in advance for your help.

 

Simon



0



Thanks! That fixes the problem.

Here's a slightly simpler version of delMissRows() that works just as well:

proc delMissRows(x);
 local mask;

 mask = sumr(x .== miss(0,0)); // number of missing entries per row
 mask = mask .< cols(x); // 1 if a row has some non-missing entries
 retp(selif(x,mask)); // returns only those rows where mask .== 1
endp;

Your Answer

3 Answers

1

I tried this program below and a few combinations (more curves, only one negative element, without using a plotcontrol struct) on Windows 7 and Linux with GAUSS 13.0.3. In all cases the x axis ranged from the minimum x value to the maximum x value.

struct plotControl myPlot;
myPlot = plotGetDefaults("xy");

x = seqa(1960, 0.25, 53*4);
y = cos(seqa(0.1, 0.1, rows(x)));
plotxy(myPlot, x,y);

Does this display correctly for you? Could you save your x and y variables as .fmt files with the save command and send them to support.

1

This is a problem related to all of the columns being passed into plotXY that have only missing values. This has already been fixed in version 13.1 which will be released in January 2013.

As a workaround here is a procedure to remove all rows that only contain missing values.

new;
struct plotControl myPlot;
myplot = plotGetDefaults("xy");
load rawdataF;
PlotSetLegend(&myplot,"off");
x = seqa(2009-0.25*cols(rawdataF),.25,cols(rawdataF));
plotXY(myPlot, x, delMissRows(rawdataF)');


proc delMissRows(x);
	local mask, idx, xout, rtrim, xctr;
	
	//Which rows have as many missings as columns
	mask = sumr(x .== miss(0,0));
	
	//Preallocate output matrix
	rtrim = sumc(mask .== cols(x));
	xout = zeros(rows(x) - rtrim, cols(x));
	
	//Fill in xout
	xctr = 1;
	for i(1, rows(x), 1);
		if mask[i] != cols(x);
			xout[xctr, .] = x[i,.];
			xctr = xctr + 1;
		endif;
	endfor;
	
	retp(xout);	
endp;
0

Hi Jason.

Thanks for your answer. Your example displays perfectly for me.

I've tried to create a single example that reproduces the problem, using my original data saved in .fmt format as you suggested. (I can't figure out how to attach the .fmt file to this forum post, so I'll send that separately by e-mail.) Here's a program that should reproduce the problem.

new;
struct plotControl myPlot;
myplot = plotGetDefaults("xy");
load rawdataF;
PlotSetLegend(&myplot,"off");
plotxy(myplot,seqa(2009-0.25*cols(rawdataF),.25,cols(rawdataF)),rawdataF');

This gives me a plot whose horizontal axis starts at 0, despite the fact that rawdataF is a 157x170 matrix.

 

Thanks in advance for your help.

 

Simon

0

Thanks! That fixes the problem.

Here's a slightly simpler version of delMissRows() that works just as well:

proc delMissRows(x);
 local mask;

 mask = sumr(x .== miss(0,0)); // number of missing entries per row
 mask = mask .< cols(x); // 1 if a row has some non-missing entries
 retp(selif(x,mask)); // returns only those rows where mask .== 1
endp;

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy