 # Axes cross at 0?

I cannot find this in the documentation (though I am sure it's in there somewhere!).  Is there an equivalent to the old _pcross global control variable in GAUSS graphics?  In the old PQG,  _pcross = 1 would have the axes cross at 0.

I would like to plot points in the 4 quadrants of R2.  I am sure I could do a work-around (shut off the x- and y-axes, draw vertical and horizontal lines at 0 etc) but I'm wondering if there's a simpler way?

Thanks

0

There is not, at this time, an automatic way to draw the axes at zero.

However, the new plotAddHLine and plotAddVLine functions make it a little easier.

For example:

``````x = seqa(-3, 0.1, 60);
y = cos(x);

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

// Turn off external axis
plotSetAxesPen(&plt, 0);

// Turn on light grid at major ticks
plotSetGridPen(&plt, "major", 1, "light gray", 1);

// Draw data
plotXY(plt, x, y);

// Add black horizontal and vertical lines at zero
plotSetLinePen(&plt, 1, "black");

You can make it simpler for yourself by creating a procedure that does most of the work for this for you like this:

``````x = seqa(-3, 0.1, 60);
y = cos(x);

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

plotSetTitle(&plt, "Custom title", "arial", 18);

plotXYZeroAxis(plt, x, y);

proc (0) = plotXYZeroAxis(struct plotControl plt, x, y);

// Turn off external axis
plotSetAxesPen(&plt, 0);

// Turn on light grid at major ticks
plotSetGridPen(&plt, "major", 1, "light gray", 1);

// Draw data
plotXY(plt, x, y);

// Add black horizontal and vertical lines at zero
plotSetLinePen(&plt, 1, "black");
endp;``````

What is nice about that is that you can still make customizations, but you don't have to redo the work of the axes and zero lines each time.

Let us know if you have any more questions! aptech

1,728

0 I think I have a better solution. Here is the code:

``````new;
cls;

nobs = 50;
x = rndn(nobs, 1) .* 3;
y = rndn(nobs, 1);

struct plotControl plt;
plt = plotGetDefaults("scatter");

// Set minimum and maximum of x-axis
plotSetXRange(&plt, -15, 15);

// Set distance between x-axis tick labels
plotSetXTicInterval(&plt, 5);

// Set minimum and maximum of y-axis
plotSetYRange(&plt, -4, 4);

// Set distance between y-axis tick labels
plotSetYTicInterval(&plt, 2);

plotScatter0(plt, x, y);

proc (0) = plotScatter0(struct plotControl plt, x, y);
local range, tic_lab;
// Turn off external axis
plotSetAxesPen(&plt, 0);
plotSetTicLabelFont(&plt, "arial", 0, "white");

// Turn on light grid at major ticks
plotSetGridPen(&plt, "major", 1, "light gray", 1);

// Draw data
plotScatter(plt, x, y);

range = (plt.xAxis.axisRange - plt.xAxis.axisRange);

tic_lab = seqa(plt.xAxis.axisRange, plt.xAxis.tics, 1 + ceil(abs(range / plt.xAxis.tics)));
for i(1, rows(tic_lab), 1);
endfor;

range = (plt.yAxis.axisRange - plt.yAxis.axisRange);
tic_lab = seqa(plt.yAxis.axisRange, plt.yAxis.tics, 1 + ceil(abs(range / plt.yAxis.tics)));
for i(1, rows(tic_lab), 1);
endfor;

// Add black horizontal and vertical lines at zero
plt = plotGetDefaults("xy");
plotSetLinePen(&plt, 1, "black");
endp;`````` aptech

1,728

0

There is not, at this time, an automatic way to draw the axes at zero.

However, the new plotAddHLine and plotAddVLine functions make it a little easier.

For example:

``````x = seqa(-3, 0.1, 60);
y = cos(x);

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

// Turn off external axis
plotSetAxesPen(&plt, 0);

// Turn on light grid at major ticks
plotSetGridPen(&plt, "major", 1, "light gray", 1);

// Draw data
plotXY(plt, x, y);

// Add black horizontal and vertical lines at zero
plotSetLinePen(&plt, 1, "black");

You can make it simpler for yourself by creating a procedure that does most of the work for this for you like this:

``````x = seqa(-3, 0.1, 60);
y = cos(x);

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

plotSetTitle(&plt, "Custom title", "arial", 18);

plotXYZeroAxis(plt, x, y);

proc (0) = plotXYZeroAxis(struct plotControl plt, x, y);

// Turn off external axis
plotSetAxesPen(&plt, 0);

// Turn on light grid at major ticks
plotSetGridPen(&plt, "major", 1, "light gray", 1);

// Draw data
plotXY(plt, x, y);

// Add black horizontal and vertical lines at zero
plotSetLinePen(&plt, 1, "black");
endp;``````

What is nice about that is that you can still make customizations, but you don't have to redo the work of the axes and zero lines each time.

Let us know if you have any more questions! aptech
1,728
0 I think I have a better solution. Here is the code:

``````new;
cls;

nobs = 50;
x = rndn(nobs, 1) .* 3;
y = rndn(nobs, 1);

struct plotControl plt;
plt = plotGetDefaults("scatter");

// Set minimum and maximum of x-axis
plotSetXRange(&plt, -15, 15);

// Set distance between x-axis tick labels
plotSetXTicInterval(&plt, 5);

// Set minimum and maximum of y-axis
plotSetYRange(&plt, -4, 4);

// Set distance between y-axis tick labels
plotSetYTicInterval(&plt, 2);

plotScatter0(plt, x, y);

proc (0) = plotScatter0(struct plotControl plt, x, y);
local range, tic_lab;
// Turn off external axis
plotSetAxesPen(&plt, 0);
plotSetTicLabelFont(&plt, "arial", 0, "white");

// Turn on light grid at major ticks
plotSetGridPen(&plt, "major", 1, "light gray", 1);

// Draw data
plotScatter(plt, x, y);

range = (plt.xAxis.axisRange - plt.xAxis.axisRange);

tic_lab = seqa(plt.xAxis.axisRange, plt.xAxis.tics, 1 + ceil(abs(range / plt.xAxis.tics)));
for i(1, rows(tic_lab), 1);
endfor;

range = (plt.yAxis.axisRange - plt.yAxis.axisRange);
tic_lab = seqa(plt.yAxis.axisRange, plt.yAxis.tics, 1 + ceil(abs(range / plt.yAxis.tics)));
for i(1, rows(tic_lab), 1);
endfor;

// Add black horizontal and vertical lines at zero
plt = plotGetDefaults("xy");
plotSetLinePen(&plt, 1, "black");
endp;`````` aptech
1,728

### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.