python - 类似于seaborn在情节中的色调功能?
问题描述
geo1 = go.Scatter(
x=geo['Year'],
y=geo['Number'],
mode='lines',
marker=dict(color=geo['Geographical region'],size=4, showscale=False),
name='geo',
showlegend=True)
data = [geo1]
layout = dict(
title='Working VISA in UK by Regions',
xaxis=dict(title='Year'),
yaxis=dict(title='Number'), showlegend=True)
fig = dict(data=data, layout=layout)
iplot(fig)
我想要的是在 seaborn 中使用与“hue”类似的功能:
如何按不同颜色的区域进行绘图编码?
解决方案
由于您使用的是 pandas,我建议使用 Plotly Express。在这种情况下,代码非常简单直观:
import plotly.express as px
fig = px.line(geo, x="Year", y="Number", color="Geographical region",
line_group="Geographical region")
fig.show()
或者,从 4.8 版本开始,您甚至可以简单地通过编写以下代码来替换 pandas 的默认绘图后端:
import pandas as pd
pd.options.plotting.backend = "plotly" # just once at the beginning
geo.plot.line(x="Year", y="Number", color="Geographical region",
line_group="Geographical region")
推荐阅读
- origen-sdk - 在 Flow.create {} 中调用接口
- python - Dockerfile python无法打开文件
- django - 如何在 Django 中为整个页面创建类似管理员的外观?
- java - 如何仅记录部分异常?
- google-apps-script - 如何创建记录开始和结束时间数据的脚本
- javascript - 得到承诺的总和
- mysql - 将值与 JSON_EXTRACT 进行比较
- python - 恢复MacOS系统Python3版本
- mysql - 无法从 MYSQL 工作台打开我的jawsDb
- javascript - 在Angular中选中或取消选中时,如何在每个复选框下显示或隐藏div标签?