N8_*_*der 9 python plotly plotly-python
我想为Python中的绘图创建一个具有n种颜色的颜色图,它应该从一种颜色淡入另一种颜色。所有默认颜色图只有 10 个离散值,但我正在寻找具有 n > 10 个离散值的颜色图。
>>> px.colors.sequential.Plasma_r
['#f0f921',
'#fdca26',
'#fb9f3a',
'#ed7953',
'#d8576b',
'#bd3786',
'#9c179e',
'#7201a8',
'#46039f',
'#0d0887']
Run Code Online (Sandbox Code Playgroud)
有没有办法将连续的地图分成n部分?
ves*_*and 10
如果您不介意RGB颜色,那么这n_colors
是一种方法。下面是 15 种颜色的示例,灰度介于'rgb(0, 0, 0)'
和之间'rgb(255, 255, 255)'
:
n_colors('rgb(0, 0, 0)', 'rgb(255, 255, 255)', 15, colortype='rgb')
Run Code Online (Sandbox Code Playgroud)
'rgb(0, 0, 255)'
这是蓝色和红色之间 25 种颜色的示例'rgb(255, 0, 0)'
:
n_colors('rgb(0, 0, 255)', 'rgb(255, 0, 0)', 25, colortype = 'rgb')
Run Code Online (Sandbox Code Playgroud)
import numpy as np
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import datetime
from plotly.colors import n_colors
pd.set_option('display.max_rows', None)
pd.options.plotting.backend = "plotly"
# greys15 = n_colors('rgb(0, 0, 0)', 'rgb(255, 255, 255)', 15, colortype='rgb')
redVSblue = n_colors('rgb(0, 0, 255)', 'rgb(255, 0, 0)', 25, colortype = 'rgb')
fig = go.Figure()
# for i, c in enumerate(greys15):
for i, c in enumerate(redVSblue):
fig.add_bar(x=[i], y = [i+1], marker_color = c, showlegend = False)
f = fig.full_figure_for_development(warn=False)
fig.show()
Run Code Online (Sandbox Code Playgroud)
S.R*_*S.R 10
与接受的响应类似,但能够使用本教程中可以找到的内置名称
colors
n_colors
包含可以视为 的列表list
。
import plotly.express as px
n_colors = 25
colors = px.colors.sample_colorscale("turbo", [n/(n_colors -1) for n in range(n_colors)])
Run Code Online (Sandbox Code Playgroud)
这是完整的示例:
import plotly.graph_objects as go
import plotly.express as px
n_colors = 25
colors = px.colors.sample_colorscale("turbo", [n/(n_colors -1) for n in range(n_colors)])
fig = go.Figure()
# for i, c in enumerate(greys15):
for i, c in enumerate(colors):
fig.add_bar(x=[i], y = [15], marker_color = c, showlegend = False, name=c)
f = fig.full_figure_for_development(warn=False)
fig.show()
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13710 次 |
最近记录: |