Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Basemap-从shapefile添加文本_Python_Matplotlib_Matplotlib Basemap - Fatal编程技术网

Python Basemap-从shapefile添加文本

Python Basemap-从shapefile添加文本,python,matplotlib,matplotlib-basemap,Python,Matplotlib,Matplotlib Basemap,在阅读了关于注释和添加文本的文章之后,我仍然遇到了一些问题 shapefile_info = m.readshapefile('/path/to/shapefile', 'shapefile_name') for info, shape in zip(m.points_info, m.points): print info, shape 读入shapefile并打印出信息(使用上述代码),我们得到以下输出: {'LABELTYPE':'ONE','LABELNAME':'Start P

在阅读了关于注释和添加文本的文章之后,我仍然遇到了一些问题

shapefile_info = m.readshapefile('/path/to/shapefile', 'shapefile_name')
for info, shape in zip(m.points_info, m.points):
    print info, shape
读入shapefile并打印出信息(使用上述代码),我们得到以下输出:

{'LABELTYPE':'ONE','LABELNAME':'Start Point'}(2274311.7551607937759422.9640236866)

{'LABELTYPE':'TWO','LABELNAME':'End Point'}(1839892.6558604166947255.0800333266)

使用下面的代码

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

l_one, l_two = 0, 0

m = Basemap(projection = 'merc', llcrnrlat= -2, urcrnrlat= 52, llcrnrlon= -137,\
            urcrnrlon= -58, lat_ts=40,resolution='i') 
m.shadedrelief()
m.drawcoastlines(linewidth=0.5)
m.drawcountries(linewidth=0.5)
m.drawstates(linewidth=0.5) 
m.drawparallels(np.arange(-90, 90, 10), linewidth = 0.2, 
                labels = [True, False, True, False], fontsize = 'x-small')
m.drawmeridians(np.arange(-180, 180, 10), linewidth = 0.2, 
                labels = [False, False, False, True], fontsize = 'x-small')

m.readshapefile('/path/to/shapefile', 'shapefile_name')
shapefile_info = m.readshapefile('/path/to/shapefile', 'shapefile_name')
for info, shape in zip(m.points_info, m.points):
    x, y = zip(shape)
    if info['LABELTYPE'] == 'ONE':
        m.plot(x, y, c = 'k', ms = 9., ls = "", mew = 1.,
                label = 'Start Point' if l_one == 0 else "_no-legend_")
        x, y = m(y[0], x[0])
        plt.plot(x, y, info['LABELNAME'])
        l_one += 1
    if info['LABELTYPE'] == 'TWO':
        m.plot(x, y, c = 'c', ms = 9., ls = "", mew = 1.,
                label = 'End Point' if l_two == 0 else "_no-legend_")
        x, y = m(y[0], x[0])
        plt.plot(x, y, info['LABELNAME'])
        l_two += 1
我得到以下错误:
非法格式字符串“起始点”;两个线型符号


为什么我会出现这个错误,我该如何着手修复它,以便能够将字典中的文本放到绘图上?

将一些文本放在
(x,y)
位置,您可以使用它来代替
plt.plot()
(如
plot
绘制线条图,而不是文本)

或者在这种情况下

plt.text(x, y, info['LABELNAME'])

要在位置
(x,y)
放置一些文本,您可以使用而不是
plt.plot()
(因为
plot
绘制的是线条图,而不是文本)

或者在这种情况下

plt.text(x, y, info['LABELNAME'])