如何在不出现 ValueError 的情况下使用 plotly 库进行绘图?
How can I plot by using plotly library without getting ValueError?
我有问题。
我导入了需要的库
aerial = pd.read_csv("C://Users//bilim//Python//DATAI Team//3) Data Visualization//operations.csv")
import plotly.plotly as py
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
import plotly.graph_objs as go
# ATTACK
aerial["color"] = ""
aerial.color[aerial.Country == "USA"] = "rgb(0,116,217)"
aerial.color[aerial.Country == "GREAT BRITAIN"] = "rgb(255,65,54)"
aerial.color[aerial.Country == "NEW ZEALAND"] = "rgb(133,20,75)"
aerial.color[aerial.Country == "SOUTH AFRICA"] = "rgb(255,133,27)"
data = [dict(
type='scattergeo',
lon = aerial['Takeoff Longitude'],
lat = aerial['Takeoff Latitude'],
hoverinfo = 'text',
text = "Country: " + aerial.Country + " Takeoff Location: "+aerial["Takeoff Location"]+" Takeoff Base: " + aerial['Takeoff Base'],
mode = 'markers',
marker=dict(
sizemode = 'area',
sizeref = 1,
size= 10 ,
line = dict(width=1,color = "white"),
color = aerial["color"],
opacity = 0.7),
)]
layout = dict(
title = 'Countries Take Off Bases ',
hovermode='closest',
geo = dict(showframe=False, showland=True, showcoastlines=True, showcountries=True,
countrywidth=1, projection=dict(type='Mercator'),
landcolor = 'rgb(217, 217, 217)',
subunitwidth=1,
showlakes = True,
lakecolor = 'rgb(255, 255, 255)',
countrycolor="rgb(5, 5, 5)")
)
fig = go.Figure(data=data, layout=layout)
iplot(fig)
错误是:
值错误:
scattergeo.marker 的 'color' 属性 收到无效元素
无效元素包括:['', '', '', '', '', '', '', '', '', '']
错误来自这行代码:aerial["color"] = ""
。如果您确实打算使用它来定义标记颜色,则需要为 aerial["color"]
(例如 ["red", "blue", "green", ...]
)分配一些值。
我有问题。 我导入了需要的库
aerial = pd.read_csv("C://Users//bilim//Python//DATAI Team//3) Data Visualization//operations.csv")
import plotly.plotly as py
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
import plotly.graph_objs as go
# ATTACK
aerial["color"] = ""
aerial.color[aerial.Country == "USA"] = "rgb(0,116,217)"
aerial.color[aerial.Country == "GREAT BRITAIN"] = "rgb(255,65,54)"
aerial.color[aerial.Country == "NEW ZEALAND"] = "rgb(133,20,75)"
aerial.color[aerial.Country == "SOUTH AFRICA"] = "rgb(255,133,27)"
data = [dict(
type='scattergeo',
lon = aerial['Takeoff Longitude'],
lat = aerial['Takeoff Latitude'],
hoverinfo = 'text',
text = "Country: " + aerial.Country + " Takeoff Location: "+aerial["Takeoff Location"]+" Takeoff Base: " + aerial['Takeoff Base'],
mode = 'markers',
marker=dict(
sizemode = 'area',
sizeref = 1,
size= 10 ,
line = dict(width=1,color = "white"),
color = aerial["color"],
opacity = 0.7),
)]
layout = dict(
title = 'Countries Take Off Bases ',
hovermode='closest',
geo = dict(showframe=False, showland=True, showcoastlines=True, showcountries=True,
countrywidth=1, projection=dict(type='Mercator'),
landcolor = 'rgb(217, 217, 217)',
subunitwidth=1,
showlakes = True,
lakecolor = 'rgb(255, 255, 255)',
countrycolor="rgb(5, 5, 5)")
)
fig = go.Figure(data=data, layout=layout)
iplot(fig)
错误是: 值错误: scattergeo.marker 的 'color' 属性 收到无效元素 无效元素包括:['', '', '', '', '', '', '', '', '', '']
错误来自这行代码:aerial["color"] = ""
。如果您确实打算使用它来定义标记颜色,则需要为 aerial["color"]
(例如 ["red", "blue", "green", ...]
)分配一些值。