I am trying to plot California counties and color them by their FIPS code. The sample code from the GeoPandas website is:
chicago.plot(
column="POP2010",
legend=True,
legend_kwds={"label": "Population in 2010", "orientation": "horizontal"},
)
That code works. My code is
ca_counties.plot(column='COUNTYFP',
legend=True,
legend_kwds={"label": "FIPS", "orientation": "horizontal"},
)
That code returns an error message that TypeError: Legend.__init__() got an unexpected keyword argument 'label'
. Unless I am going crazy, the spelling of "orientation" is correct and everything else matches. I have also removed the comma after the }
but that does not work. I am able to plot ca.counties
with the "FIPS" label as well as use the ``loc" keyword to move the legend around. It is only when I try to change the orientation that I have a problem.
Since the chicago example works, I do not think it is something with the version of geopandas
and matplotlib
I have installed. I updated them anyway.
In case it matters, I am using JupyterLab via Anaconda Navigator. The error exists whether I execute the code from the cell or paste it into the console and execute in the console.
What am I misunderstanding?
I started to make a MWE script and in so doing figured out the problem. COUNTYFP
was an object dtype, so matplotlib was creating discrete colors. For a reason I don't understand, orientation
only works for colorbars. Chaning COUNTYFP
to numeric data solved the problem.