0

I am trying to plot the following directly from an example online (listed below). I have geopandas, GDAL, fiona, shapely, rtree, and pyproj all installed based off of the recommendations in this Install Python geopandas failed .

from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

import plotly.express as px

fig = px.choropleth_mapbox(df, geojson=counties, locations='fips', color='unemp',
                           color_continuous_scale="Viridis",
                           range_color=(0, 12),
                           mapbox_style="carto-positron",
                           zoom=3, center = {"lat": 37.0902, "lon": -95.7129},
                           opacity=0.5,
                           labels={'unemp':'unemployment rate'}
                          )
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

It is code pulled directly from: https://plotly.com/python/mapbox-county-choropleth/ enter image description here

I keep getting this error. Can someone help me understand what I need to do to fix this.

     ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-102-d2bce8a3a6d7> in <module>
         10 import plotly.express as px
         11 
    ---> 12 fig = px.choropleth_mapbox(df, geojson=counties, locations='fips', color='unemp',
         13                            color_continuous_scale="Viridis",
         14                            range_color=(0, 12),
    
    ~\anaconda3\lib\site-packages\plotly\express\_chart_types.py in choropleth_mapbox(data_frame, geojson, featureidkey, locations, color, hover_name, hover_data, custom_data, animation_frame, animation_group, category_orders, labels, color_discrete_sequence, color_discrete_map, color_continuous_scale, range_color, color_continuous_midpoint, opacity, zoom, center, mapbox_style, title, template, width, height)
       1139     hover_data=None,
       1140     custom_data=None,
    -> 1141     animation_frame=None,
       1142     animation_group=None,
       1143     category_orders=None,
    
    ~\anaconda3\lib\site-packages\plotly\express\_core.py in make_figure(args, constructor, trace_patch, layout_patch)
       2051     layout_patch["legend"] = dict(tracegroupgap=0)
       2052     if trace_name_labels:
    -> 2053         layout_patch["legend"]["title_text"] = ", ".join(trace_name_labels)
       2054     if args["title"]:
       2055         layout_patch["title_text"] = args["title"]
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in update_layout(self, dict1, overwrite, **kwargs)
        963         return self["data"]
        964 
    --> 965     @data.setter
        966     def data(self, new_data):
        967 
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in update(self, dict1, overwrite, **kwargs)
       4254         # ### _change_callbacks ###
       4255         # A dict from tuples of child property path tuples to lists
    -> 4256         # of callbacks that should be executed whenever any of these
       4257         # properties is modified
       4258         self._change_callbacks = {}
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in _perform_update(plotly_obj, update_obj, overwrite)
       3347 
       3348         # Handle layout
    -> 3349         # -------------
       3350         result["layout"] = BaseFigure._to_ordered_dict(self._layout)
       3351 
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in __setitem__(self, prop, value)
       4993             if invalid_props:
       4994                 if len(invalid_props) == 1:
    -> 4995                     prop_str = "property"
       4996                     invalid_str = repr(invalid_props[0])
       4997                 else:
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in __setitem__(self, prop, value)
       4009             annotation, shape_type, shape_args, annotation_kwargs
       4010         )
    -> 4011         self.add_shape(
       4012             row=row,
       4013             col=col,
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in _set_compound_prop(self, prop, val)
       4394                 from _plotly_utils.basevalidators import (
       4395                     CompoundValidator,
    -> 4396                     CompoundArrayValidator,
       4397                 )
       4398 
    
    ~\anaconda3\lib\site-packages\_plotly_utils\basevalidators.py in validate_coerce(self, v, skip_invalid)
       2737         if v == {} or isinstance(v, self.data_class) and v.to_plotly_json() == {}:
       2738             # Replace empty template with {'data': {'scatter': [{}]}} so that we can
    -> 2739             # tell the difference between an un-initialized template and a template
       2740             # explicitly set to empty.
       2741             return self.data_class(data_scatter=[{}])
    
    ~\anaconda3\lib\site-packages\_plotly_utils\basevalidators.py in validate_coerce(self, v, skip_invalid, _validate)
       2448 
       2449         elif isinstance(v, dict):
    -> 2450             v = self.data_class(v, skip_invalid=skip_invalid, _validate=_validate)
       2451 
       2452         elif isinstance(v, self.data_class):
    
    ~\anaconda3\lib\site-packages\plotly\graph_objs\layout\_template.py in __init__(self, arg, data, layout, **kwargs)
        321         _v = layout if layout is not None else _v
        322         if _v is not None:
    --> 323             self["layout"] = _v
        324 
        325         # Process unknown kwargs
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in __setitem__(self, prop, value)
       4009             annotation, shape_type, shape_args, annotation_kwargs
       4010         )
    -> 4011         self.add_shape(
       4012             row=row,
       4013             col=col,
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in _set_compound_prop(self, prop, val)
       4394                 from _plotly_utils.basevalidators import (
       4395                     CompoundValidator,
    -> 4396                     CompoundArrayValidator,
       4397                 )
       4398 
    
    ~\anaconda3\lib\site-packages\_plotly_utils\basevalidators.py in validate_coerce(self, v, skip_invalid, _validate)
       2444 
       2445     def validate_coerce(self, v, skip_invalid=False, _validate=True):
    -> 2446         if v is None:
       2447             v = self.data_class()
       2448 
    
    ~\anaconda3\lib\site-packages\plotly\graph_objs\_layout.py in __init__(self, arg, activeshape, angularaxis, annotations, annotationdefaults, autosize, bargap, bargroupgap, barmode, barnorm, boxgap, boxgroupgap, boxmode, calendar, clickmode, coloraxis, colorscale, colorway, datarevision, direction, dragmode, editrevision, extendfunnelareacolors, extendpiecolors, extendsunburstcolors, extendtreemapcolors, font, funnelareacolorway, funnelgap, funnelgroupgap, funnelmode, geo, grid, height, hiddenlabels, hiddenlabelssrc, hidesources, hoverdistance, hoverlabel, hovermode, images, imagedefaults, legend, mapbox, margin, meta, metasrc, modebar, newshape, orientation, paper_bgcolor, piecolorway, plot_bgcolor, polar, radialaxis, scene, selectdirection, selectionrevision, separators, shapes, shapedefaults, showlegend, sliders, sliderdefaults, spikedistance, sunburstcolorway, template, ternary, title, titlefont, transition, treemapcolorway, uirevision, uniformtext, updatemenus, updatemenudefaults, violingap, violingroupgap, violinmode, waterfallgap, waterfallgroupgap, waterfallmode, width, xaxis, yaxis, **kwargs)
       6096         _v = funnelmode if funnelmode is not None else _v
       6097         if _v is not None:
    -> 6098             self["funnelmode"] = _v
       6099         _v = arg.pop("geo", None)
       6100         _v = geo if geo is not None else _v
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in _process_kwargs(self, **kwargs)
       4850         prop : str
       4851             The name of a direct child of this object
    -> 4852         value
       4853             New property value
       4854         Returns
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in _process_kwargs(self, **kwargs)
       3547             If True, produce a string containing a complete HTML document
       3548             starting with an <html> tag.  If False, produce a string containing
    -> 3549             a single <div> element.
       3550         animation_opts: dict or None (default None)
       3551             dict of custom animation parameters to be passed to the function
    
    ~\anaconda3\lib\site-packages\plotly\basedatatypes.py in _raise_on_invalid_property_error(self, *args)
       4215             Invalid props/values to raise on
       4216         """
    -> 4217         # ### _skip_invalid ##
       4218         # If True, then invalid properties should be skipped, if False then
       4219         # invalid properties will result in an exception
    
    ValueError: Invalid property specified for object of type plotly.graph_objs.Layout: 'autotypenumbers'
4
  • what version of plotly are you using, using the latest version is working perfectly fine for me Commented Apr 15, 2021 at 3:44
  • @AS11 plotly-4.14.3 Commented Apr 15, 2021 at 3:47
  • 1
    This may just be a problem that is caused by another package, maybe try running this in an environment with only the requirements that are needed for this specific file. Commented Apr 15, 2021 at 4:03
  • I need to isolate the failure. First, let's see if we can display other maps in plotly. Let's start with this one. Here is the description of the parameter 'autontypenumbers', which is the error message. Let's try :px.choropleth_mapbox(...,autotypenumbers='strict'). Commented Apr 15, 2021 at 5:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.