# d3 scatter plot, y axis issue

**URL:** <https://talk.observablehq.com/t/d3-scatter-plot-y-axis-issue/2451>\
**Category:** Help\
**Created:** [October 7, 2019, 10:17am UTC](https://talk.observablehq.com/t/d3-scatter-plot-y-axis-issue/2451 "2019-10-07T10:17:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![quantlib](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/quantlib/32/2154_2.png) [@quantlib](https://talk.observablehq.com/u/quantlib)\
**Post date:** [October 7, 2019, 10:17am UTC](https://talk.observablehq.com/t/d3-scatter-plot-y-axis-issue/2451/1 "2019-10-07T10:17:56Z")

</div>

Hello, I’m new to observable notebook, apologies if this has been asked before.

I was trying to plot a scatter chart for random numbers, notebook link: [https://observablehq.com/@quantlib/random-numbers-and-dimensionality](https://observablehq.com/@quantlib/random-numbers-and-dimensionality)

in second d3 chart, the y axis text is not displayed, and y axis is upside down.  
i googed around and tried many different code, it’s always the same

btw for the same data, i plotted using microsoft excel, it supposed to look like this:

 ![2019-10-07%2018_17_05-](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/9/9e0e8ed9b9a73741ad10c141402dbf673e2adc4b.png)

please helpl, thank you!

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [October 7, 2019, 1:24pm UTC](https://talk.observablehq.com/t/d3-scatter-plot-y-axis-issue/2451/2 "2019-10-07T13:24:57Z")

</div>

Hi and welcome!

Here’s a diff with a few fixes to the issues you mentioned:  
[https://observablehq.com/compare/fb240bfc888da4e6@135...dbcf4c98eafe5632@152](https://observablehq.com/compare/fb240bfc888da4e6@135...dbcf4c98eafe5632@152)

(I only applied them to the first two charts, hopefully you can see what to do for the rest.)

Some comments:

> the y axis text is not displayed,

This is because you were missing some required attributes on the `text` element, namely the `x` attribute and the `fill` (or `stroke`) attribute. This aside, the axis labels were being drawn outside the SVG, which I solved by setting `overflow: visible`. There are also other ways to fix this, see the examples in the forum post below.

> y axis is upside down.

Your function for the `cy` attribute was reversed (recall that `y=0` is the top of the image, and `y=height` is the bottom). I changed the `cx` and `cy` functions to use the `x` and `y` scales that you already defined.

This recent forum post has some more resources for axes in D3 charts on Observable:

> [@Axis do not show](https://talk.observablehq.com/t/axis-do-not-show/2439):
>
> 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](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…

---

<div class="post-metadata">

**Author:** ![quantlib](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/quantlib/32/2154_2.png) [@quantlib](https://talk.observablehq.com/u/quantlib)\
**Post date:** [October 7, 2019, 1:29pm UTC](https://talk.observablehq.com/t/d3-scatter-plot-y-axis-issue/2451/3 "2019-10-07T13:29:07Z")

</div>

@bgchen, wow, awesome! I’m learning new things of D3.js, thanks a lot!

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [October 7, 2019, 6:57pm UTC](https://talk.observablehq.com/t/d3-scatter-plot-y-axis-issue/2451/4 "2019-10-07T18:57:01Z")

</div>

> [@bgchen](#):
>
> the axis labels were being drawn outside the SVG, which I solved by setting `overflow: visible`

Wait, what?! I didn’t even know you could do that! 😃

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [October 7, 2019, 7:55pm UTC](https://talk.observablehq.com/t/d3-scatter-plot-y-axis-issue/2451/5 "2019-10-07T19:55:10Z")

</div>

Yeah, I learned that from @mbostock’s post in the other thread!
