user10835338
user10835338

Reputation:

How can I plot by using plotly library without getting ValueError?

I am having a problem. I imported needed libraries

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)

The error is: ValueError: Invalid element(s) received for the 'color' property of scattergeo.marker Invalid elements include: ['', '', '', '', '', '', '', '', '', '']

Upvotes: 0

Views: 104

Answers (1)

user11989081
user11989081

Reputation: 8663

The error comes from this line of code: aerial["color"] = "". You would need to assign some values to aerial["color"] (e.g. ["red", "blue", "green", ...]) if you actually intend to use it to define the marker colors.

Upvotes: 1

Related Questions