[GIS] Assign colour to the shapefile with matplotlib

matplotlibogrpython

import shapefile as shp
import matplotlib.pyplot as pltsf = shp.Reader("D:/New folder1/21_8_2016.shp")

plt.figure()
for shape in sf.shapeRecords():
    x = [i[0] for i in shape.shape.points[:]]
    y = [i[1] for i in shape.shape.points[:]]
    plt.plot(x, y)
plt.show()

this shows my hsapefile in alot colours how do i assign it a single colour ?

Best Answer

The plot function has colour options. You can simply add the arguments, as follows:

import shapefile as shp
import matplotlib.pyplot as pltsf = shp.Reader("D:/New folder1/21_8_2016.shp")

plt.figure()
for shape in sf.shapeRecords():
    x = [i[0] for i in shape.shape.points[:]]
    y = [i[1] for i in shape.shape.points[:]]
    plt.plot(x, y, color = 'red')
plt.show()

Check this link for more details.