如何以散点图形式表示散点矩阵中的轴极限?

时间:2020-08-23 04:11:53

标签: python jupyter-notebook plotly plotly-python

我有以下几行代码:

import plotly.express as px
fig = px.scatter_matrix(df_fases,
    dimensions=["titanite", "amphibole", "epidote", "chlorite","garnet","ilmenite","rutile"], width=1000,
    height=1000, title="Rangos de umbral (vmax) por mineral")
fig.update_traces(diagonal_visible=False)
fig.update_traces(marker=dict(size=4))

[enter image description here][1]

fig.show()

...但是当我分别用fig.update_xaxes (range = [1.5, 4.5])fig.update_yaxes (range = [3, 9])更改x和y轴时,它仅更改了散点矩阵图的某些图形。对于所有图形?

image scatter matrix

1 个答案:

答案 0 :(得分:0)

您似乎有7个功能,因此您将需要使用fig.update_layout并遍历xaxis1 ... xaxis7以及yaxis1 ... yaxis7。我们已针对您的特定问题对功能的数量进行了硬编码,但是您可以根据需要进行修改。

fig.update_layout({"xaxis"+str(i+1): dict(range = [1.5, 4.5]) for i in range(7)})
fig.update_layout({"yaxis"+str(i+1): dict(range = [3, 9]) for i in range(7)})

下面是虹膜数据集上相同事物的一个示例,在这里我设置了每个图的范围:

import plotly.express as px
df = px.data.iris()
fig = px.scatter_matrix(df,
    dimensions=["sepal_width", "sepal_length", "petal_width", "petal_length"],
    color="species", symbol="species",
    title="Scatter matrix of iris data set",
    labels={col:col.replace('_', ' ') for col in df.columns}) # remove underscore

fig.update_layout({"xaxis"+str(i+1): dict(range = [0, 10]) for i in range(4)})
fig.update_layout({"yaxis"+str(i+1): dict(range = [0, 10]) for i in range(4)})
fig.update_traces(diagonal_visible=False)
fig.show()

enter image description here