#๐Ÿ”’ Create a scatter plot graph

6 messages ยท Page 1 of 1 (latest)

rose boltBOT
#

@proud pecan

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

proud pecan
#
        const cell = d3.select(this);

        x.domain(domainByDimension[p.x]);
        y.domain(domainByDimension[p.y]);

        cell.append("rect")
            .attr("class", "frame")
            .attr("x", padding / 2)
            .attr("y", padding / 2)
            .attr("width", size - padding)
            .attr("height", size - padding);

        if (p.x === p.y) {
            const histogram = d3.histogram()
                .domain(x.domain())
                .thresholds(x.ticks(20));

            const bins = histogram(data.map(d => d[p.x]));

            const yHist = d3.scaleLinear()
                .domain([0, d3.max(bins, d => d.length)])
                .range([size - padding / 2, padding / 2]);

            const bar = cell.selectAll(".bar")
                .data(bins)
                .enter().append("g")
                .attr("class", "bar")
                .attr("transform", d => `translate(${x(d.x0)},${yHist(d.length)})`);

            bar.append("rect")
                .attr("x", 1)
                .attr("width", d => x(d.x1) - x(d.x0) - 1)
                .attr("height", d => size - padding / 2 - yHist(d.length))
                .attr("class", "histogram");
        } else if (dimensions.indexOf(p.x) > dimensions.indexOf(p.y)) {
            const corr = pearsonCorrelation(data.map(d => d[p.x]), data.map(d => d[p.y]));
            cell.append("text")
                .attr("x", size / 2)
                .attr("y", size / 2)
                .attr("dy", ".35em")
                .style("text-anchor", "middle")
                .text(corr.toFixed(2));
        } else {
            cell.selectAll("circle")
                .data(data)
                .enter().append("circle")
                .attr("cx", d => x(d[p.x]))
                .attr("cy", d => y(d[p.y]))
                .attr("r", 3);
        } ```
rich crypt
rose boltBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ Create a scatter plot graph