vasili111
vasili111

Reputation: 6930

How to adjust number of ticks?

Here is my code:

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Bar(
    name='Group 1',
    x=['Var 1', 'Var 2', 'Var 3'], y=[3, 6, 4],
    error_y=dict(type='data', array=[1, 0.5, 1.5]),
    width=0.15
))
fig.add_trace(go.Bar(
    name='Group 2',
    x=['Var 1', 'Var 2', 'Var 3'], y=[4, 7, 3],
    error_y=dict(type='data', array=[0.5, 1, 2]),
    width=0.15
))
fig.update_layout(barmode='group')
fig.show()

output:

enter image description here


Now I need adjust number of ticks for y axis, like 1, 1.5, 2, 2.5, or make it less, like 2,4,6.

I tried to change y0 and dy arguments nothing is changes:

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Bar(
    name='Group 1',
    x=['Var 1', 'Var 2', 'Var 3'], y=[3, 6, 4],
    y0 = 0,
    dy = 50,
    error_y=dict(type='data', array=[1, 0.5, 1.5]),
    width=0.15
))
fig.add_trace(go.Bar(
    name='Group 2',
    x=['Var 1', 'Var 2', 'Var 3'], y=[4, 7, 3],
    y0 = 0,
    dy = 50,
    error_y=dict(type='data', array=[0.5, 1, 2]),
    width=0.15
))
fig.update_layout(barmode='group')
fig.show()



Question: How to adjust nuber of tiks for y axis for my first code?

Upvotes: 1

Views: 2445

Answers (1)

bigbounty
bigbounty

Reputation: 17368

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Bar(
    name='Group 1',
    x=['Var 1', 'Var 2', 'Var 3'], y=[3, 6, 4],
    error_y=dict(type='data', array=[1, 0.5, 1.5]),
    width=0.15
))
fig.add_trace(go.Bar(
    name='Group 2',
    x=['Var 1', 'Var 2', 'Var 3'], y=[4, 7, 3],
    error_y=dict(type='data', array=[0.5, 1, 2]),
    width=0.15
))
fig.update_layout(barmode='group',yaxis=dict(
        tickmode = 'linear',
        tick0 = 1,
        dtick = 0.5
    ))
fig.show()

The trick here is to use the parameter - yaxis during the update_layout. Same goes for xaxis tick properties

enter image description here

Upvotes: 3

Related Questions