5

I would like to plot a shapefile using geopandas. I would like to have the thickness of the lines in accordance with an attribute in the shapefile. I am using the following command for that:

shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=shp_sub['Case1_2'], edgecolor='0.8', vmin=0, vmax=1)

This means that the thickness and the colour code should match each other.

I have tried this:

shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=1, edgecolor='0.8', vmin=0, vmax=1)

Image 1

When I try this, I don't get the one-to-one.

shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5), linewidth=shp_sub['Case1_2'], edgecolor='0.8', vmin=0, vmax=1)

Image 2

APhillips
  • 1,175
  • 9
  • 17
ShGh
  • 67
  • 1
  • 5

1 Answers1

1

It looks like your 'Case1_2' attribute is not numeric or not numeric within a range that changes the linewidth meaningfully. Linewidths between 0 and ~15 are probably all you are interested in plotting. If you create a new attribute that is numeric based (e.g., based on stream order), then using the column values to set linewidth should work.

shp_sub['order'] = 1. # best to be numeric, not a geometry
shp_sub['order'].iloc[10] = 4. # change the value of one of the attributes
shp_sub.plot(column='Case1_2', cmap='BuGn', figsize=(5,5),
             linewidth=shp_sub['order'], edgecolor='0.8', # edgecolor another column with data?
             vmin=0, vmax=1)

Or you can scale one of your existing columns to be within the range of useful linewidths:

import numpy as np
temp_array = shp_sub['Case1_2'].values
# Scale from 0 to 1
temp_array = (np.max(temp_array)-temp_array)/(np.max(temp_array)-np.min(temp_array))

max_width = 10 # set maximum line width to use

shp_sub['lw'] = max_width*temp_array
# and then plot with linewidth=shp_sub['lw']
befpy
  • 31
  • 2