HI All,
I have nearly given up learning d3.js in Observable as I cannot seem to make any progress beyond plotting simple points and bars. I cannot seem to plot axes let alone do anything more (very frustrating!)
Here is the notebook I tried to work on while learning about d3.
https://observablehq.com/@arinbasu/d3-understanding
I cannot seem to ‘view’ the axes.
What am I doing wrongly?
Here is the code:
svg_scatter = d3
.select(cont5)
.append('svg')
.selectAll('circle')
.data(data2)
.enter()
.append('circle')
.attr('cx', d => {
return d.disp;
})
.attr('cy', d => {
return d.mpg;
})
.attr('r', 10)
.attr('fill', 'black')
.append('g')
.call(d3.axisBottom(x_scale))
.call(d3.axisLeft(y_scale))
x_scale and y_scale are as follows:
x_scale = d3
.scaleLinear()
.domain([60, 400])
.range([0, w])
y scale
y_scale = d3
.scaleLinear()
.domain([10, 30])
.range([h, 0])
data = d3.csv(
"https://gist.githubusercontent.com/seankross/a412dfbd88b3db70b74b/raw/5f23f993cd87c283ce766e7ac6b329ee7cc2e1d1/mtcars.csv"
)
(data2 is where I have converted the character vectors in the mtcars data to floating point numbers for mpg, cyl, and disp variables)
w, h, margin are width, height, and margins where
w = 600
h = 400
margin = 50
I’d greatly appreciate some insights.
Best,
Arindam Basu