我有一个色阶
colorscale2 = ['hsl(-2221.0, 60.0%, 98.0%)',
'hsl(-2192.0460921843687, 59.791583166332664%, 97.88777555110221%)',
'hsl(-2163.0921843687374, 59.58316633266533%, 97.7755511022044%)',
'hsl(-2134.138276553106, 59.37474949899799%, 97.66332665330661%)',
'hsl(-2105.184368737475, 59.166332665330664%, 97.55110220440882%)',
'hsl(-2076.2304609218436, 58.95791583166333%, 97.43887775551102%)',
'hsl(-2047.2765531062123, 58.74949899799599%, 97.32665330661322%)',
'hsl(-2018.3226452905812, 58.54108216432866%, 97.21442885771543%)',
'hsl(-1989.36873747495, 58.33266533066132%, 97.10220440881764%)',
'hsl(-1960.4148296593187, 58.124248496993985%, 96.98997995991984%)',
'hsl(-1931.4609218436874, 57.91583166332666%, 96.87775551102204%)',
'hsl(-1902.5070140280561, 57.70741482965932%, 96.76553106212425%)',
'hsl(-1873.5531062124248, 57.498997995991985%, 96.65330661322645%)',
'hsl(-1844.5991983967936, 57.29058116232465%, 96.54108216432866%)',
'hsl(-1815.6452905811623, 57.08216432865731%, 96.42885771543087%)',
'hsl(-1786.6913827655312, 56.87374749498998%, 96.31663326653306%)',
'hsl(-1757.7374749499, 56.66533066132264%, 96.20440881763527%)',
'hsl(-1728.7835671342687, 56.45691382765531%, 96.09218436873748%)']
但我收到以下错误:
File "C:\ProgramData\Miniconda3\lib\site-packages\_plotly_utils\basevalidators.py", line 1100, in validate_coerce
self.raise_invalid_val(v)
File "C:\ProgramData\Miniconda3\lib\site-packages\_plotly_utils\basevalidators.py", line 243, in raise_invalid_val
valid_clr_desc=self.description()))
ValueError:
Invalid value of type 'builtins.str' received for the 'fillcolor' property of scatter
Received value: 'hsl(-2221.0, 60.0%, 98.0%)'
The 'fillcolor' property is a color and may be specified as:
- A hex string (e.g. '#ff0000')
- An rgb/rgba string (e.g. 'rgb(255,0,0)')
- An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
- An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
- A named CSS color:
aliceblue, antiquewhite, aqua, aquamarine, azure,
beige, bisque, black, blanchedalmond, blue,
blueviolet, brown, burlywood, cadetblue,
chartreuse, chocolate, coral, cornflowerblue,
cornsilk, crimson, cyan, darkblue, darkcyan,
darkgoldenrod, darkgray, darkgrey, darkgreen,
darkkhaki, darkmagenta, darkolivegreen, darkorange,
darkorchid, darkred, darksalmon, darkseagreen,
darkslateblue, darkslategray, darkslategrey,
darkturquoise, darkviolet, deeppink, deepskyblue,
dimgray, dimgrey, dodgerblue, firebrick,
floralwhite, forestgreen, fuchsia, gainsboro,
ghostwhite, gold, goldenrod, gray, grey, green,
greenyellow, honeydew, hotpink, indianred, indigo,
ivory, khaki, lavender, lavenderblush, lawngreen,
lemonchiffon, lightblue, lightcoral, lightcyan,
lightgoldenrodyellow, lightgray, lightgrey,
lightgreen, lightpink, lightsalmon, lightseagreen,
lightskyblue, lightslategray, lightslategrey,
lightsteelblue, lightyellow, lime, limegreen,
linen, magenta, maroon, mediumaquamarine,
mediumblue, mediumorchid, mediumpurple,
mediumseagreen, mediumslateblue, mediumspringgreen,
mediumturquoise, mediumvioletred, midnightblue,
mintcream, mistyrose, moccasin, navajowhite, navy,
oldlace, olive, olivedrab, orange, orangered,
orchid, palegoldenrod, palegreen, paleturquoise,
palevioletred, papayawhip, peachpuff, peru, pink,
plum, powderblue, purple, red, rosybrown,
royalblue, saddlebrown, salmon, sandybrown,
seagreen, seashell, sienna, silver, skyblue,
slateblue, slategray, slategrey, snow, springgreen,
steelblue, tan, teal, thistle, tomato, turquoise,
violet, wheat, white, whitesmoke, yellow,
yellowgreen
出什么问题了?我已经在下面包含了我的整个代码,
import plotly.plotly as py
from plotly.figure_factory._county_choropleth import create_choropleth
import numpy as np
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/chessybo/Oil-Spill-map/468bd2205d85c7b0bfb4ebcd4bc4bf0ba408efb4/RRC_Spill_table/county_name%20%26%20fips%20%26%20net%20loss%20%26%20count%20(ordered%20by%20district%20%26%20grouped).csv')
colorscale2 = ['hsl(-2221.0, 60.0%, 98.0%)',
'hsl(-2192.0460921843687, 59.791583166332664%, 97.88777555110221%)',
'hsl(-2163.0921843687374, 59.58316633266533%, 97.7755511022044%)',
'hsl(-2134.138276553106, 59.37474949899799%, 97.66332665330661%)',
'hsl(-2105.184368737475, 59.166332665330664%, 97.55110220440882%)',
'hsl(-2076.2304609218436, 58.95791583166333%, 97.43887775551102%)',
'hsl(-2047.2765531062123, 58.74949899799599%, 97.32665330661322%)',
'hsl(-2018.3226452905812, 58.54108216432866%, 97.21442885771543%)',
'hsl(-1989.36873747495, 58.33266533066132%, 97.10220440881764%)',
'hsl(-1960.4148296593187, 58.124248496993985%, 96.98997995991984%)',
'hsl(-1931.4609218436874, 57.91583166332666%, 96.87775551102204%)',
'hsl(-1902.5070140280561, 57.70741482965932%, 96.76553106212425%)',
'hsl(-1873.5531062124248, 57.498997995991985%, 96.65330661322645%)',
'hsl(-1844.5991983967936, 57.29058116232465%, 96.54108216432866%)',
'hsl(-1815.6452905811623, 57.08216432865731%, 96.42885771543087%)',
'hsl(-1786.6913827655312, 56.87374749498998%, 96.31663326653306%)',
'hsl(-1757.7374749499, 56.66533066132264%, 96.20440881763527%)',
'hsl(-1728.7835671342687, 56.45691382765531%, 96.09218436873748%)']
endpts = [120, 240, 360, 480, 600, 720, 840, 960, 1080, 1225, 2225, 3225, 4225, 5225, 6225]
fips = df['fips'].tolist()
values = df['Net spill volume (BBL)'].tolist()
count=df['number_of_oil_spills'].tolist()
x=values
fig = create_choropleth(
fips=fips, values=values,
binning_endpoints=endpts,
colorscale=colorscale2,
show_state_data=False,
show_hover=True, centroid_marker={'opacity': 0},
scope=['TX'],
state_outline={'color': 'rgb(15, 15, 55)', 'width': 3},
asp=2.9, title='Oil Spills from 12/1/16 - 5/14/18',
legend_title='Net spill Volume (BBL)'
)
fig['layout']['legend'].update({'x': 0})
fig['layout']['annotations'][0].update({'x': -0.12, 'xanchor': 'left'})
py.plot(fig, filename='oil spill net loss')
答案 0 :(得分:1)
从https://www.w3schools.com/colors/colors_hsl.asp开始,hsl的第一个值是hue,范围从0到360.0。
相关功能不希望您拥有的数据。也许您可能想研究一下并进行一些预处理。