Black Lives Matter. Please consider donating to Black Girls Code today.

Restrict axis ticks labels to only show int values

I have a plot with a y axis


It should only show integer values such as 1,2,3,4


Unfortunately when I zoom in floats are displayed (1.5,2.5,3.5)


Is there a way of telling plotly to only display ints


I tried using a list of predefined tickvals but this list is too long when zoomed out fully than the labels overlap


Thanks

2 Likes

You could try using tickformat like in http://codepen.io/etpinard/pen/OpyjjJ

This is nice but it produces multiple numbers which are the same.

β€œ1 1.5 2” turns into β€œ1 1 2”

Ideally I was looking for a method of turning β€œ1 1.5 2” into just β€œ1 2”

Thanks

There’s probably a way to do this. You can play around with all the possible format settings on http://bl.ocks.org/zanarmstrong/05c1e95bf7aa16c4768e

Thanks etienne your recommeded link worked very well

The format that removes rounded ints was d3.format(",d")

The graph looks much nicer now

2 Likes

In python, along:

fig = Figure(
    data = data,
    layout = Layout(
        barmode='stack',
        yaxis={'tickformat': ',d'},
2 Likes