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

2 Answers



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");
plotAddVLine(plt, 0);
plotAddHLine(plt, 0);

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");
    plotAddVLine(plt, 0);
    plotAddHLine(plt, 0);
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,773


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[1] - plt.xAxis.axisRange[2]);

    tic_lab = seqa(plt.xAxis.axisRange[1], plt.xAxis.tics[3], 1 + ceil(abs(range / plt.xAxis.tics[3])));
    for i(1, rows(tic_lab), 1);
        plotAddTextBox(ntos(tic_lab[i]),tic_lab[i], 0);
    endfor;

    range = (plt.yAxis.axisRange[1] - plt.yAxis.axisRange[2]);
    tic_lab = seqa(plt.yAxis.axisRange[1], plt.yAxis.tics[3], 1 + ceil(abs(range / plt.yAxis.tics[3])));
    for i(1, rows(tic_lab), 1);
        plotAddTextBox(ntos(tic_lab[i]),0, tic_lab[i]);
    endfor;

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

aptech

1,773

Your Answer

2 Answers

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");
plotAddVLine(plt, 0);
plotAddHLine(plt, 0);

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");
    plotAddVLine(plt, 0);
    plotAddHLine(plt, 0);
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!

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[1] - plt.xAxis.axisRange[2]);

    tic_lab = seqa(plt.xAxis.axisRange[1], plt.xAxis.tics[3], 1 + ceil(abs(range / plt.xAxis.tics[3])));
    for i(1, rows(tic_lab), 1);
        plotAddTextBox(ntos(tic_lab[i]),tic_lab[i], 0);
    endfor;

    range = (plt.yAxis.axisRange[1] - plt.yAxis.axisRange[2]);
    tic_lab = seqa(plt.yAxis.axisRange[1], plt.yAxis.tics[3], 1 + ceil(abs(range / plt.yAxis.tics[3])));
    for i(1, rows(tic_lab), 1);
        plotAddTextBox(ntos(tic_lab[i]),0, tic_lab[i]);
    endfor;

    // Add black horizontal and vertical lines at zero
    plt = plotGetDefaults("xy");
    plotSetLinePen(&plt, 1, "black");
    plotAddVLine(plt, 0);
    plotAddHLine(plt, 0);
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.