python - 在情节中调整色标位置
问题描述
我想使用并行类别图显示具有重复连接的数据框的两列之间的连接。问题是,我不知道如何调整颜色条的位置,这样它就不会打断其余的标签。我正在添加更多上下文的代码:
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
您可以通过其属性移动颜色条的位置。
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()
推荐阅读
- scala - Spark cassandra 连接器 - 在 where 条件下访问 RDD
- angular - 找不到工作区文件('angular.json')
- angular - 使用 ng-if 隐藏某个元素
- html - 将 HTML 文件导入 React 的组件
- python - Python 循环比 Pandas 快
- javascript - 动态填充一个 Promise.all()
- java - 线程的易失性
- visual-studio - 如何撤消 Visual Studio 更新
- python - 如何在python中使用selenium webdriver从excel导入数据
- javascript - 通过 jquery ajax 调用时谷歌图表不显示