Using this map of NYC I'd like to change Manhattan to be bright blue. But when I change the individual patch color of Manhattan all the other patch colors change too. This was unexpected to me.
How do you change the color of one individual patch?
from matplotlib import pyplot as pltimport geopandas as gpd# Import the shape filenybb = gpd.GeoDataFrame.from_file('nybb.shp')# Plot all of NYBBnybb_plot = nybb.plot()# Change the patch colorsfor p_ny in nybb_plot.patches: p_ny.set_color("#111111") p_ny.set_alpha(0.6)# Change the patch outlinesfor line in nybb_plot.lines: line.set_linewidth(0.25) line.set_alpha(0.9) line.set_color("#d3d3d3")# Separate manhattan from the GeoDataFramemanhattan = nybb.loc[nybb.BoroName == "Manhattan"]# Plot Manhattan over the topman_plot = manhattan.plot()# Change the patch color of the newly plotted Manhattanfor p_mh in man_plot.patches: p_mh.set_color("#33ccff")# Pretty things upax = plt.gca()ax.xaxis.set_visible(False)ax.yaxis.set_visible(False)plt.show()
أكثر...
How do you change the color of one individual patch?
from matplotlib import pyplot as pltimport geopandas as gpd# Import the shape filenybb = gpd.GeoDataFrame.from_file('nybb.shp')# Plot all of NYBBnybb_plot = nybb.plot()# Change the patch colorsfor p_ny in nybb_plot.patches: p_ny.set_color("#111111") p_ny.set_alpha(0.6)# Change the patch outlinesfor line in nybb_plot.lines: line.set_linewidth(0.25) line.set_alpha(0.9) line.set_color("#d3d3d3")# Separate manhattan from the GeoDataFramemanhattan = nybb.loc[nybb.BoroName == "Manhattan"]# Plot Manhattan over the topman_plot = manhattan.plot()# Change the patch color of the newly plotted Manhattanfor p_mh in man_plot.patches: p_mh.set_color("#33ccff")# Pretty things upax = plt.gca()ax.xaxis.set_visible(False)ax.yaxis.set_visible(False)plt.show()
أكثر...