在绘图中调整色标位置
adjust color scale location in plotly
我想使用平行类别图显示我的数据框中具有重复连接的两列之间的连接。问题是,我不知道如何调整颜色条的位置,以免打断其余标签。
我正在添加更多上下文的代码:
import plotly.express as px
from Models.Linear import Linear
model = Linear('YAP1')
index = model.get_index()
m, n = model.get_full_A().shape
df = pd.DataFrame(index=np.arange(m), columns=['Expression', 'Methylation'])
df['Data Set'] = index.get_level_values(0).values.flatten()
df['Expression'] = index.get_level_values(1).values.flatten()
df['Methylation'] = index.get_level_values(2).values.flatten()
df['size'] = how_much_to_satisfy()
fig = px.parallel_categories(df, dimensions=['Expression', 'Methylation'],
color="size", color_continuous_scale=px.colors.sequential.Inferno,
width=100, )
fig.update_layout(autosize=False, width=1200, height=1500,
margin=dict(l=500, r=300, b=65, t=90, pad=4), font=dict(size=15))
谢谢!
您可以通过x
attribute移动颜色条的位置。
fig.layout['coloraxis']['colorbar']['x'] = 1.15
我无权访问您的数据集,但这是 Plotly 的一个示例,它显示了同样的问题,即颜色条与标签重叠。
import plotly.express as px
df = px.data.tips()
df['day'].replace({'Sun': 'Sunday יום ראשון', 'Sat': 'Saturday יום שבת', 'Thur': 'Thursday יום חמישי',
'Fri': 'Friday יום שישי'}, inplace=True)
fig = px.parallel_categories(df, dimensions=['sex', 'smoker', 'day'],
color="size", color_continuous_scale=px.colors.sequential.Inferno,
labels={'sex':'Payer sex', 'smoker':'Smokers at the table', 'day':'Day of week'},
)
fig.show()
fig.layout['coloraxis']['colorbar']['x'] = 1.15
fig.show()
我想使用平行类别图显示我的数据框中具有重复连接的两列之间的连接。问题是,我不知道如何调整颜色条的位置,以免打断其余标签。 我正在添加更多上下文的代码:
import plotly.express as px
from Models.Linear import Linear
model = Linear('YAP1')
index = model.get_index()
m, n = model.get_full_A().shape
df = pd.DataFrame(index=np.arange(m), columns=['Expression', 'Methylation'])
df['Data Set'] = index.get_level_values(0).values.flatten()
df['Expression'] = index.get_level_values(1).values.flatten()
df['Methylation'] = index.get_level_values(2).values.flatten()
df['size'] = how_much_to_satisfy()
fig = px.parallel_categories(df, dimensions=['Expression', 'Methylation'],
color="size", color_continuous_scale=px.colors.sequential.Inferno,
width=100, )
fig.update_layout(autosize=False, width=1200, height=1500,
margin=dict(l=500, r=300, b=65, t=90, pad=4), font=dict(size=15))
谢谢!
您可以通过x
attribute移动颜色条的位置。
fig.layout['coloraxis']['colorbar']['x'] = 1.15
我无权访问您的数据集,但这是 Plotly 的一个示例,它显示了同样的问题,即颜色条与标签重叠。
import plotly.express as px
df = px.data.tips()
df['day'].replace({'Sun': 'Sunday יום ראשון', 'Sat': 'Saturday יום שבת', 'Thur': 'Thursday יום חמישי',
'Fri': 'Friday יום שישי'}, inplace=True)
fig = px.parallel_categories(df, dimensions=['sex', 'smoker', 'day'],
color="size", color_continuous_scale=px.colors.sequential.Inferno,
labels={'sex':'Payer sex', 'smoker':'Smokers at the table', 'day':'Day of week'},
)
fig.show()
fig.layout['coloraxis']['colorbar']['x'] = 1.15
fig.show()