I embarked on creating a Minimum Working Example (MWE) script, and in the process, I stumbled upon the root of the issue. The COUNTYFP
column had an object data type, causing matplotlib to generate discrete colors. Strangely, the orientation
parameter only seems to function for colorbars. Once I converted COUNTYFP
to numeric data, the problem was resolved.
Here's the code snippet that demonstrates the fix:
import geopandas as gpd import matplotlib.pyplot as plt # Read shapefile data = gpd.read_file("path/to/shapefile.shp") # Convert COUNTYFP column to numeric data['COUNTYFP'] = data['COUNTYFP'].astype(int) # Plot choropleth map data.plot(column='COUNTYFP', legend=True, legend_kwds={'orientation': 'horizontal'}) plt.show()
In summary, the culprit was the object data type of the COUNTYFP
column. By converting it to numeric, matplotlib was able to generate a continuous colorbar, and the orientation
parameter functioned as expected.