Search code examples
d3.jsscalelogarithm

d3 log scale does not display


I want to display a contour plot with a logarithmic scale on both axes. I found this nice example to perform this task:

http://plnkr.co/edit/f1VThUpkHxUzxOBXmTCr?p=preview

However when I change the scale to logarithmic scale

var x = d3.scale.log()
    .range([0, width]);

instead of

var x = d3.scale.linear()
    .range([0, width]);

The axis simply disappear. I thought that the problem was that log(0) = -infinity however it does not change anything if I start at 1.

What is the problem?


Solution

  • You want to change the domain to not start from 0 (I presume you changed the range)

    x.domain([1, dx]);
    

    Plunker - http://plnkr.co/edit/RTzBztpVpR2GYXiVUogb?p=preview


    enter image description here