gpt4 book ai didi

python - Plotly:如何更改 3D 曲面图的配色方案?

转载 作者:行者123 更新时间:2023-12-04 12:23:05 24 4
gpt4 key购买 nike

我想在 plotly python 中更改 3D 曲面图的配色方案。 Plotly 默认分配配色方案,如下图所示。
Plot 1
这是我的代码

import import plotly.graph_objects as go
import pandas as pd

data = pd.read_csv('\Data.csv')
data.set_index("years", inplace = True)
figure = go.Figure(data=[go.Surface(z=data.values)])
figure.update_layout(
scene = dict(
xaxis = dict(
title = 'Months',
#nticks = 5,
autorange='reversed',
showgrid=True,
gridwidth=1,
gridcolor='Blue',
ticktext = data.columns,
tickvals= list(range(0,data.shape[1]))),


yaxis = dict(
title = 'years',
showgrid=True,
gridwidth=1,
gridcolor='Blue',
ticktext = data.index,
tickvals= list(range(0,data.shape[0]))),

zaxis = dict(
title = 'Discharge (Cumecs)',
#showgrid=True,
gridwidth=1,
gridcolor='Blue')),
tilte = 'Plot 1'
)

最佳答案

您可以通过 colorscale 轻松更改配色方案在

go.Surface(colorscale ='<color>')
这是一个使用 colorscale='Blues 的示例:
fig = go.Figure(data=[go.Surface(z=z_data.values, colorscale ='Blues')])
阴谋
enter image description here
您的色阶选项是(但不一定限于):

Greys,YlGnBu,Greens,YlOrRd,Bluered,RdBu,Reds,Blues,Picnic,Rainbow,Portland,Jet,Hot,Blackbody,Earth,Electric,Viridis,Cividis.


示例代码:
import plotly.graph_objects as go

import pandas as pd

# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')

fig = go.Figure(data=[go.Surface(z=z_data.values, colorscale ='Blues')])

fig.update_layout(title='Mt Bruno Elevation', autosize=False,
width=500, height=500,
margin=dict(l=65, r=50, b=65, t=90))
f = fig.full_figure_for_development(warn=False)


fig.show()

关于python - Plotly:如何更改 3D 曲面图的配色方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66044846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com