How to plot a Plotly graph with hexadecimal value in the Y axis

Viewed 37

I have a data frame as shown below.I need to plot this using plotly.My Y axis value is hexadecimal.

Device_ID   OTP_TRIM_BIT
    
    TTK_536     0x01
    TTK_537     0x01
    TTK_538     0x01
    TTK_542     0x01
    TTK_543     0x01
    FFK_571     0x0e
    FFK_572     0x0e
    FFK_573     0x0e
    FFK_574     0x0e
    FFK_575     0x0e
    SSK_586     0x02
    SSK_587     0x02
    SSK_588     0x01
    SSK_589     0x01
    SSK_590     0x02
    FSK_601     0x01
    FSK-602     0x01
    FSK_603     x01
    FSK_604     0x01
    FSK_605     0x01
    SFK_616     0x00
    SFK_617     0x00
    SFK_618     0x00
    SFK_619     0x0f

May I know how to approach this.I need device id in X axis and trim bit in Y axis

1 Answers

You can convert the hex strings using int with base 16:

import plotly.express as px

fig = px.bar(x=df.Device_ID, y=df.OTP_TRIM_BIT.apply(lambda x: int(x, 16)))
fig.write_html('first_figure.html', auto_open=True)

enter image description here

or using the pandas plotly plotting backend:

pd.options.plotting.backend = "plotly"
fig = df.assign(OTP_TRIM_BIT=df.OTP_TRIM_BIT.apply(lambda x: int(x, 16))).plot.bar(x='Device_ID', y='OTP_TRIM_BIT')
fig.show()

(if the trim bit entry of device ID FSK_603 is indeed x01 instead of 0x01 you can use for instance .apply(lambda x: int(x if x[0]=='0' else '0' + x, 16))) instead)

Related