Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Plotly how to show axis values outside your dataset's max value?

import plotly.express as px
import pandas as pd

df = pd.DataFrame(dict(
    r=[1,2,3],
    theta=['a', 'b','c']))

fig = px.line_polar(df, r=[1,2,3], theta=['a','b','c'], line_close=True)
fig.update_polars(radialaxis_tickvals=[1,2,3,4,5], radialaxis_tickmode='array')
fig.show()

I have code like so that is able to generate a polar chart that looks like below

enter image description here

However what I want is to ensure that the maximum value of my tickvals is the maximum on the chart. So even though 3 is the highest value in this particular dataset, I want it to show tickvals 4 and 5 on the chart itself. This is so I can visually see that the 3 here is lower than the maximum otherwise when compared to other charts, at a glance it would look like 3 or 5 both meet the maximum.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the radialaxis_range argument.

import plotly.express as px
import pandas as pd

df = pd.DataFrame(dict(r=[1, 2, 3], theta=["a", "b", "c"]))

fig = px.line_polar(df, r=[1, 2, 3], theta=["a", "b", "c"], line_close=True)

fig.update_polars(
    radialaxis_tickvals=[1, 2, 3, 4, 5],
    radialaxis_tickmode="array",
    radialaxis_range=[0, 5],  # Set the range of radial axis to always go up to 5
)

fig.show()

polar plot

See here for the docs: https://plotly.com/python/reference/layout/polar/#layout-polar-radialaxis-range

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading