JSXGraph logo
JSXGraph
JSXGraph share

Share

Axis logarithmic scale
QR code
<iframe 
    src="http://jsxgraph.uni-bayreuth.de/share/iframe/axis-logarithmic-scale" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Axis logarithmic scale" 
    allowfullscreen
></iframe>
This code has to
<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution ShareAlike 4.0 International License.
    https://creativecommons.org/licenses/by-sa/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    const board = JXG.JSXGraph.initBoard(BOARDID, {
        boundingbox: [-5, 6, 5, -4],
        axis: false    // Turn off default axes
    });
    // Horizontal axis with linear scale and same look
    // as default axes
    var attr = JXG.Options.board.defaultAxes.x;
    attr.ticks.drawZero = false;
    var xAxis = board.create('axis', [[0, 0], [1, 0]], attr);
    
    // Vertical axis with logarithmic scale and same look
    // as default axes.
    attr = JXG.Options.axis;
    var yAxis = board.create('line', [[0, 0], [0, 1]], attr);
    
    attr = JXG.Options.board.defaultAxes.y.ticks,
    attr.insertTicks = true;
    attr.drawLabels = true;
    attr.drawZero = false;
    attr.generateLabelText = function(tick, zero) {
        var value = Math.pow(10, Math.round(tick.usrCoords[2] - zero.usrCoords[2]));
        return this.formatLabelText(value);
    };
    
    var ticksY = board.create('ticks', [yAxis, 1], attr);
    
    // Plot two functions in logarithmic scale
    var post = (x) => JXG.Math.log10(x);
    var f1 = (x) => x * x;
    var f2 = (x) => Math.exp(x);
    
    board.create('functiongraph', [(x) => post(f1(x))], {
        name: 'x^2',
        withLabel: true
    });
    
    board.create('functiongraph', [(x) => post(f2(x))], {
        name: 'e^x',
        withLabel: true,
        strokeColor: 'red'
    });
    
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-sa/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-5, 6, 5, -4],
    axis: false    // Turn off default axes
});
// Horizontal axis with linear scale and same look
// as default axes
var attr = JXG.Options.board.defaultAxes.x;
attr.ticks.drawZero = false;
var xAxis = board.create('axis', [[0, 0], [1, 0]], attr);

// Vertical axis with logarithmic scale and same look
// as default axes.
attr = JXG.Options.axis;
var yAxis = board.create('line', [[0, 0], [0, 1]], attr);

attr = JXG.Options.board.defaultAxes.y.ticks,
attr.insertTicks = true;
attr.drawLabels = true;
attr.drawZero = false;
attr.generateLabelText = function(tick, zero) {
    var value = Math.pow(10, Math.round(tick.usrCoords[2] - zero.usrCoords[2]));
    return this.formatLabelText(value);
};

var ticksY = board.create('ticks', [yAxis, 1], attr);

// Plot two functions in logarithmic scale
var post = (x) => JXG.Math.log10(x);
var f1 = (x) => x * x;
var f2 = (x) => Math.exp(x);

board.create('functiongraph', [(x) => post(f1(x))], {
    name: 'x^2',
    withLabel: true
});

board.create('functiongraph', [(x) => post(f2(x))], {
    name: 'e^x',
    withLabel: true,
    strokeColor: 'red'
});
<jsxgraph width="100%" aspect-ratio="1 / 1" title="Axis logarithmic scale" description="This construction was copied from JSXGraph examples database: BTW HERE SHOULD BE A GENERATED LINKuseGlobalJS="false">
   /*
   This example is licensed under a 
   Creative Commons Attribution ShareAlike 4.0 International License.
   https://creativecommons.org/licenses/by-sa/4.0/
   
   Please note you have to mention 
   The Center of Mobile Learning with Digital Technology
   in the credits.
   */
   
   const board = JXG.JSXGraph.initBoard(BOARDID, {
       boundingbox: [-5, 6, 5, -4],
       axis: false    // Turn off default axes
   });
   // Horizontal axis with linear scale and same look
   // as default axes
   var attr = JXG.Options.board.defaultAxes.x;
   attr.ticks.drawZero = false;
   var xAxis = board.create('axis', [[0, 0], [1, 0]], attr);
   
   // Vertical axis with logarithmic scale and same look
   // as default axes.
   attr = JXG.Options.axis;
   var yAxis = board.create('line', [[0, 0], [0, 1]], attr);
   
   attr = JXG.Options.board.defaultAxes.y.ticks,
   attr.insertTicks = true;
   attr.drawLabels = true;
   attr.drawZero = false;
   attr.generateLabelText = function(tick, zero) {
       var value = Math.pow(10, Math.round(tick.usrCoords[2] - zero.usrCoords[2]));
       return this.formatLabelText(value);
   };
   
   var ticksY = board.create('ticks', [yAxis, 1], attr);
   
   // Plot two functions in logarithmic scale
   var post = (x) => JXG.Math.log10(x);
   var f1 = (x) => x * x;
   var f2 = (x) => Math.exp(x);
   
   board.create('functiongraph', [(x) => post(f1(x))], {
       name: 'x^2',
       withLabel: true
   });
   
   board.create('functiongraph', [(x) => post(f2(x))], {
       name: 'e^x',
       withLabel: true,
       strokeColor: 'red'
   });
   
</jsxgraph>

Axis logarithmic scale

Use logarithmic scale for vertical axis.
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-5, 6, 5, -4],
    axis: false    // Turn off default axes
});
// Horizontal axis with linear scale and same look
// as default axes
var attr = JXG.Options.board.defaultAxes.x;
attr.ticks.drawZero = false;
var xAxis = board.create('axis', [[0, 0], [1, 0]], attr);

// Vertical axis with logarithmic scale and same look
// as default axes.
attr = JXG.Options.axis;
var yAxis = board.create('line', [[0, 0], [0, 1]], attr);

attr = JXG.Options.board.defaultAxes.y.ticks,
attr.insertTicks = true;
attr.drawLabels = true;
attr.drawZero = false;
attr.generateLabelText = function(tick, zero) {
    var value = Math.pow(10, Math.round(tick.usrCoords[2] - zero.usrCoords[2]));
    return this.formatLabelText(value);
};

var ticksY = board.create('ticks', [yAxis, 1], attr);

// Plot two functions in logarithmic scale
var post = (x) => JXG.Math.log10(x);
var f1 = (x) => x * x;
var f2 = (x) => Math.exp(x);

board.create('functiongraph', [(x) => post(f1(x))], {
    name: 'x^2',
    withLabel: true
});

board.create('functiongraph', [(x) => post(f2(x))], {
    name: 'e^x',
    withLabel: true,
    strokeColor: 'red'
});

license

This example is licensed under a Creative Commons Attribution ShareAlike 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.