Labelling default ticks Plotly Express

I want to keep the current tick layout on my plotly express chart, but instead of having the raw values, have labels. Basically, I like the fact there’s only a few ‘main’ ticks and not a tick for every value, but I need to change the text on the labels.

I have been trying to figure this out using the ‘Array’ tickmode and sorting, but this either sorts the chart (which I don’t want), or the labels generated are unevenly spaced.

Here is my original code before I messed it up!

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>def lap_times_graph(year, d_ids, laps_df, races_df, col):
for d_id in d_ids:
times = {"x": [], "y": [], "Name": [], "Lap": [], "Time": []}
# Obtains each race the selected driver was in for the selected year
races_df = races_df.loc[races_df["year"] == year, ["race_id", "name"]]
for index, r in races_df.iterrows():
df_laps = laps_df.loc[(laps_df["race_id"] == r["race_id"]) & (laps_df["driver_id"] == d_id), ["lap", "time", "milliseconds"]]
df_laps2 = df_laps.sort_values(by="milliseconds")
for index, r1 in df_laps.iterrows():
times["x"].append(r1["milliseconds"])
times["y"].append(r["race_id"])
times["Name"].append(r["name"])
times["Lap"].append(r1["lap"])
times["Time"].append(r1["time"])
df = pd.DataFrame(data=times)
# Remove outliers
z = np.abs(stats.zscore(df['x']))
threshold = 3
outliers = df[z > threshold]
df = df.drop(outliers.index)
fig = px.strip(df, x="x", y="y",title="Lap Times<br><sub class='subtitle'>Hover over points for more details</sub>",
labels = {"x": "Lap time", "y": "Race"},
color_discrete_sequence = n_colors("rgb(255, 75, 75)", "rgb(255,255,255)", 3, colortype="rgb"), color="y",
hover_name="Name", hover_data={"x":False, "y":False, "Lap":True, "Time":True})
fig.update_layout(
showlegend = False,
yaxis = dict(
side = "right",
showticklabels = False),
xaxis = dict(
tickangle = -45)
)
col.plotly_chart(fig, use_container_width=False)
</code>
<code>def lap_times_graph(year, d_ids, laps_df, races_df, col): for d_id in d_ids: times = {"x": [], "y": [], "Name": [], "Lap": [], "Time": []} # Obtains each race the selected driver was in for the selected year races_df = races_df.loc[races_df["year"] == year, ["race_id", "name"]] for index, r in races_df.iterrows(): df_laps = laps_df.loc[(laps_df["race_id"] == r["race_id"]) & (laps_df["driver_id"] == d_id), ["lap", "time", "milliseconds"]] df_laps2 = df_laps.sort_values(by="milliseconds") for index, r1 in df_laps.iterrows(): times["x"].append(r1["milliseconds"]) times["y"].append(r["race_id"]) times["Name"].append(r["name"]) times["Lap"].append(r1["lap"]) times["Time"].append(r1["time"]) df = pd.DataFrame(data=times) # Remove outliers z = np.abs(stats.zscore(df['x'])) threshold = 3 outliers = df[z > threshold] df = df.drop(outliers.index) fig = px.strip(df, x="x", y="y",title="Lap Times<br><sub class='subtitle'>Hover over points for more details</sub>", labels = {"x": "Lap time", "y": "Race"}, color_discrete_sequence = n_colors("rgb(255, 75, 75)", "rgb(255,255,255)", 3, colortype="rgb"), color="y", hover_name="Name", hover_data={"x":False, "y":False, "Lap":True, "Time":True}) fig.update_layout( showlegend = False, yaxis = dict( side = "right", showticklabels = False), xaxis = dict( tickangle = -45) ) col.plotly_chart(fig, use_container_width=False) </code>
def lap_times_graph(year, d_ids, laps_df, races_df, col):
for d_id in d_ids:
    times = {"x": [], "y": [], "Name": [], "Lap": [], "Time": []}

    # Obtains each race the selected driver was in for the selected year
    races_df = races_df.loc[races_df["year"] == year, ["race_id", "name"]]
    for index, r in races_df.iterrows():
        df_laps = laps_df.loc[(laps_df["race_id"] == r["race_id"]) & (laps_df["driver_id"] == d_id), ["lap", "time", "milliseconds"]]
        df_laps2 = df_laps.sort_values(by="milliseconds")

        for index, r1 in df_laps.iterrows():
            times["x"].append(r1["milliseconds"])
            times["y"].append(r["race_id"])
            times["Name"].append(r["name"])
            times["Lap"].append(r1["lap"])
            times["Time"].append(r1["time"])
           
    df = pd.DataFrame(data=times)

    # Remove outliers
    z = np.abs(stats.zscore(df['x']))
    threshold = 3
    outliers = df[z > threshold]
    df = df.drop(outliers.index)

    fig = px.strip(df, x="x", y="y",title="Lap Times<br><sub class='subtitle'>Hover over points for more details</sub>",
                   labels = {"x": "Lap time", "y": "Race"}, 
                   color_discrete_sequence = n_colors("rgb(255, 75, 75)", "rgb(255,255,255)", 3, colortype="rgb"), color="y", 
                   hover_name="Name", hover_data={"x":False, "y":False, "Lap":True, "Time":True})
    
    fig.update_layout(
        showlegend = False,
        yaxis = dict(
            side = "right",
            showticklabels = False),
        xaxis = dict(
            tickangle = -45)
    )

    col.plotly_chart(fig, use_container_width=False)

Is there any way to change the labels on the default ticks? r1["Time"] Holds values with the correct format I’m looking for

An example of what I’m looking to achieve: (changes in yellow)

Thanks..

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật