Python 中的 Plotly 数据可视化入门
Alex Scriven
Data Scientist
自定义图表的方式:
color)update_layout()fig.update_layout({"title":{"text":"A New Title"}})
自定义颜色有助于:


color 参数(DataFrame 列)
fig = px.bar(data_frame=student_scores,
x="student_name",
y="score",
title="Student Scores by Student"
color="city")
fig.show()
之前的图:

之后的图:

在单变量(柱状图、直方图)中使用 plotly.express 的 color 参数:


color_discrete_map:将分类值映射到颜色的字典"red"、"green" 等$$
fig = px.bar( data_frame=student_scores, x="student_name", y="score", title="Student Scores by Student",color_discrete_map={ "Melbourne": "rgb(0,0,128)", "Sydney": "rgb(235, 207, 52)"},color="city")


$$
color_continuous_scale 指定颜色刻度。
fig = px.bar(data_frame=weekly_temps,
x="day", y="temp",
color="temp",
color_continuous_scale="inferno")
fig.show()
$$

my_scale=[("rgb(242, 238, 10)"), ("rgb(242, 95, 10)"), ("rgb(255,0,0)")]fig = px.bar(data_frame=weekly_temps, x="day", y="temp",color_continuous_scale=my_scale, color="temp")

Python 中的 Plotly 数据可视化入门