Python 如何在使用matplotlib制作的shapefile绘图上显示图例?

Python 如何在使用matplotlib制作的shapefile绘图上显示图例?,python,matplotlib,shapefile,matplotlib-basemap,geopandas,Python,Matplotlib,Shapefile,Matplotlib Basemap,Geopandas,但是我想在绘图上显示属性seg_id2。其目的是直观地识别绘图上的哪个段ID 我怎么做 数据->打印(segdat) 你尝试过ax.legend()方法吗?@PaulH当我在最后添加ax.legend()时,我得到一条消息:没有找到标签的句柄放在legend中。@PaulH我想我必须使用ax.annotate,但我不确定语法在我的情况下会是什么……你不想使用ax.annotate。理想情况下,segdat.plot有一个界面,可以向艺术家添加标签。否则。您想使用ax.legend,可能需要使用代

但是我想在绘图上显示属性
seg_id2
。其目的是直观地识别绘图上的哪个段ID

我怎么做

数据->打印(segdat)
你尝试过
ax.legend()
方法吗?@PaulH当我在最后添加ax.legend()时,我得到一条消息:
没有找到标签的句柄放在legend中。
@PaulH我想我必须使用ax.annotate,但我不确定语法在我的情况下会是什么……你不想使用
ax.annotate
。理想情况下,
segdat.plot
有一个界面,可以向艺术家添加标签。否则。您想使用ax.legend,可能需要使用代理艺术家:
f, ax = plt.subplots(1, figsize=(10, 10))
segdat.plot(ax = ax)
ax.grid(False)
DrainID  Region  tosegment2  tosegment  seg_id   seg_id2      POI_ID  \
4265        0      17    17003600       3600    3601  17003601  23977694.0   
4266        0      17    17003601       3601    3602  17003602  23977730.0   
4267        0      17    17003602       3602    3603  17003603  23977740.0   
4268        0      17    17003603       3603    3604  17003604  23977756.0   
4269        0      17    17003604       3604    3605  17003605  23977768.0   
4280        0      17    17003617       3617    3616  17003616  23978138.0   
4281        0      17    17003601       3601    3617  17003617  23978240.0   
4282        0      17    17003603       3603    3618  17003618  23978270.0   

      TOCOMID2  To_POI_ID         ToFTYPE  \
4265  23977692   23977690  ArtificialPath   
4266  23977728   23977694     StreamRiver   
4267  23977738   23977730     StreamRiver   
4268  23977754   23977740     StreamRiver   
4269  23977766   23977756     StreamRiver   
4280  23978124   23978240     StreamRiver   
4281  23977728   23977694     StreamRiver   
4282  23977754   23977740     StreamRiver   

                            ...                            start_y  TopElev  \
4265                        ...                          2953650.0    419.0   
4266                        ...                          2950720.0    450.0   
4267                        ...                          2949670.0    515.0   
4268                        ...                          2944070.0    673.0   
4269                        ...                          2938960.0   1556.0   
4280                        ...                          2954990.0   1204.0   
4281                        ...                          2956780.0    646.0   
4282                        ...                          2954410.0   1142.0   

      start_lon  start_lat         end_x         end_y  BotElev    end_lon  \
4265 -121.60876   47.22422 -1.936867e+06  2.962250e+06    315.0 -121.77018   
4266 -121.56032   47.20599 -1.926502e+06  2.953645e+06    419.0 -121.60876   
4267 -121.45534   47.21603 -1.923482e+06  2.950721e+06    450.0 -121.56032   
4268 -121.37551   47.17858 -1.915479e+06  2.949670e+06    515.0 -121.45534   
4269 -121.30617   47.14376 -1.910708e+06  2.944069e+06    673.0 -121.37551   
4280 -121.48708   47.25993 -1.922253e+06  2.956777e+06    646.0 -121.56589   
4281 -121.56589   47.26175 -1.926502e+06  2.953645e+06    419.0 -121.60876   
4282 -121.48519   47.25484 -1.915479e+06  2.949670e+06    515.0 -121.45534   

       end_lat                                           geometry  
4265  47.27419  LINESTRING (-121.608761988729 47.2242221934646...  
4266  47.22422  LINESTRING (-121.5603207212904 47.205992526363...  
4267  47.20599  LINESTRING (-121.4553369887238 47.216027726421...  
4268  47.21603  LINESTRING (-121.3755095225431 47.178575793639...  
4269  47.17858  LINESTRING (-121.3061719883217 47.143764793176...  
4280  47.26175  LINESTRING (-121.4870757220231 47.259931326970...  
4281  47.22422  LINESTRING (-121.5658905883279 47.261748327003...  
4282  47.21603  LINESTRING (-121.4851917216763 47.254842326505...  

[8 rows x 22 columns]