Search code examples
pythonplotlyplotly-python

Plotly: How to set y-axis ticklabels inside the plot / to the right of the axis?


With a plot such as this:

enter image description here

How can you set the y-axis tick-labels inside the plot, or to the right of the y-axis?

Code

import plotly.express as px

df = px.data.stocks(indexed=True)-1
fig = px.bar(df, x=df.index, y="GOOG")
fig.show()

Solution

  • This is a feature that has been asked about in numerous forms on SO the last few years - often as an addition to a more detailed question. After Plotly version 4.14 this can easily be done through, for example:

    ticklabelposition="inside top"
    

    Plot:

    enter image description here

    Complete code:

    import plotly.express as px
    
    df = px.data.stocks(indexed=True)-1
    fig = px.bar(df, x=df.index, y="GOOG")
    fig.update_yaxes(ticklabelposition="inside top", title=None)
    fig.show()