I want the currency sign as a prefix to the x-axis in a plotly subplot, the commands are fine because it works elsewhere but it just seems to play up when it integrates with the subplot functions.
import pandas as pd
import numpy as np
import plotly.graph_objs as go
from plotly.subplots import make_subplots
import random
x = np.array(["France", "Spain", "Italy", "Chile"])
df = pd.DataFrame({"country": np.repeat(x, [10,10,10,10]).tolist(),
"rating": random.sample(range(0,100),40),
"price": random.sample(range(100,1000),40)})
scatter = make_subplots(rows = 2, cols = 2, shared_yaxes = True, shared_xaxes = True,
subplot_titles = ("France", "Spain", "Italy", "Chile"),
x_title = "Price", y_title = "Rating"
)
scatter.add_trace(go.Scatter(x = df.loc[df["country"]=="France", "price"],
y = df.loc[df["country"]=="France", "rating"],
mode = "markers"),
row = 1, col = 1)
scatter.add_trace(go.Scatter(x = df.loc[df["country"]=="Spain", "price"],
y = df.loc[df["country"]=="Spain", "rating"],
mode = "markers"),
row = 1, col = 2)
scatter.add_trace(go.Scatter(x = df.loc[df["country"]=="Italy", "price"],
y = df.loc[df["country"]=="Italy", "rating"],
mode = "markers"),
row = 2, col = 1)
scatter.add_trace(go.Scatter(x = df.loc[df["country"]=="Chile", "price"],
y = df.loc[df["country"]=="Chile", "rating"],
mode = "markers"),
row = 2, col = 2)
scatter.update_layout(showlegend = False, plot_bgcolor = "white",
xaxis = dict(showtickprefix = "all", tickprefix = "£"))
scatter.show()
If I remove the shared x and y axes commands then the currency will appear only on the bottom left subplot but I don't want to remove this really.
Does anyone know any way around this, please?
Update