在matplotlib中如何覆蓋圖中外部右上角位置所示的shapefile(文件夾中可用)。 如何覆蓋matplotlib中的shapefile
3
A
回答
3
通過banderkat引用的代碼:
import matplotlib.pyplot as plt
import Image
import numpy as np
im = Image.open('Jbc4j.jpg')
width = im.size[0]
height = im.size[1]
# We need a float array between 0-1, rather than
# a uint8 array between 0-255
im = np.array(im).astype(np.float)/255
a = np.random.randint(0,100,100)
b = range(100)
fig = plt.figure(1,figsize=(5, 7), dpi=80, facecolor='w')
ax = fig.add_subplot(111)
ax.scatter(a,b)
fig.canvas.draw()
# With newer (1.0) versions of matplotlib, you can
# use the "zorder" kwarg to make the image overlay
# the plot, rather than hide behind it... (e.g. zorder=10)
fig.figimage(im, fig.bbox.xmax - width, fig.bbox.ymax - height, zorder=0)
# (Saving with the same dpi as the screen default to
# avoid displacing the logo image)
fig.savefig('temp.png', dpi=80)
plt.show()
產生以下結果(成像裁剪以節省空間)。
改變zorder=1
將放置在上面的圖像。
其他有用的參考資料:
3
您可以使用底圖工具包加載和繪製shapefile。在這裏,我將ShapeFile繪製在單獨的座標軸中,並使用'subplot2grid'將其對齊到其他座標軸的右上角。
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import matplotlib.gridspec as gridspec
def plotShapeFile():
# Lambert Conformal Conic map.
m = Basemap(llcrnrlon=-100.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57.,
projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60.,
resolution ='l',area_thresh=1000.)
# read shapefile.
shp_info = m.readshapefile('C:/basemap-1.0.6/basemap-1.0.6/examples/huralll020','hurrtracks',drawbounds=False)
# find names of storms that reached Cat 4.
names = []
for shapedict in m.hurrtracks_info:
cat = shapedict['CATEGORY']
name = shapedict['NAME']
if cat in ['H4','H5'] and name not in names:
# only use named storms.
if name != 'NOT NAMED': names.append(name)
# plot tracks of those storms.
for shapedict,shape in zip(m.hurrtracks_info,m.hurrtracks):
name = shapedict['NAME']
cat = shapedict['CATEGORY']
if name in names:
xx,yy = zip(*shape)
# show part of track where storm > Cat 4 as thick red.
if cat in ['H4','H5']:
m.plot(xx,yy,linewidth=1.5,color='r')
elif cat in ['H1','H2','H3']:
m.plot(xx,yy,color='k')
# draw coastlines, meridians and parallels.
m.drawcoastlines()
m.drawcountries()
m.drawmapboundary(fill_color='#99ffff')
m.fillcontinents(color='#cc9966',lake_color='#99ffff')
m.drawparallels(np.arange(10,70,20),labels=[1,1,0,0])
m.drawmeridians(np.arange(-100,0,20),labels=[0,0,0,1])
if __name__ == '__main__':
fig=plt.figure()
plt.subplots_adjust(wspace=0.001, hspace=0.001)
ax1=plt.subplot2grid((5,5), (0,0), colspan=4, rowspan=4)
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15,30,45, 10]
explode=(0, 0.05, 0, 0)
p1,t1,at1 = plt.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
plt.title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})
ax2=plt.subplot2grid((5,5), (0,4), colspan=1, rowspan=1)
#draw shapeFile on the current active axes, i.e. ax2
plotShapeFile()
plt.tight_layout()
plt.show()
下面是鏈接引用我用:
http://sourceforge.net/projects/matplotlib/files/matplotlib-toolkits/basemap-1.0.6/ http://matplotlib.org/basemap/users/examples.html
輸出:
相關問題
- 1. iOS蘋果地圖上的shapefile覆蓋
- 2. 覆蓋Matplotlib中的輪廓圖
- 3. 覆蓋matplotlib中的透明路徑?
- 4. Matplotlib - 金融音量覆蓋
- 5. 覆蓋matplotlib中陰謀的lineCollection - 如何讓兩者排隊。
- 6. 在matplotlib中添加音量覆蓋
- 7. 刪除重疊shapefile幾何覆蓋多數?
- 8. matplotlib:覆蓋不同尺度的地塊?
- 9. 覆蓋matplotlib的平移工具(wx)
- 10. 如何覆蓋已覆蓋的類
- 11. R-ggplot shapefile被較大的特徵覆蓋的小特徵
- 12. 覆蓋谷歌地圖上的ESRI shapefile的最佳方式?
- 13. 如何使用Matplotlib繪製覆蓋軸的製造商?
- 14. matplotlib - 如何將數組保存爲覆蓋文本的圖像?
- 15. Matplotlib - 如何覆蓋圖像上不同軸上的網格?
- 16. 如何覆蓋
- 17. 如何覆蓋?
- 18. 熊貓boxplot封面/覆蓋matplotlib圖
- 19. matplotlib清除覆蓋分散圖像
- 20. 如何覆蓋JS URL覆蓋?
- 21. 在交互式地圖上覆蓋shapefile或柵格
- 22. 如何改進XSL中的變量覆蓋/覆蓋?
- 23. 如何覆蓋jQuery-BlockUI中的覆蓋css
- 24. 覆蓋覆蓋?
- 25. 如何覆蓋UserChangeForm
- 26. 如何覆蓋CSS?
- 27. 如何覆蓋BorderBrush?
- 28. 如何覆蓋Schedulers.io()?
- 29. 如何覆蓋attr_protected?
- 30. 如何覆蓋DataAnnotations
也許你可以使用figimage,作爲描述這裏] [ 1]。 [1]:http://stackoverflow.com/questions/3609585/how-to-insert-a-small-image-on-the-corner-of-a-plot-with-matplotlib – banderkat
任何運氣提供的答案? – JSuar
@JSar感謝您的回答,抱歉我遲到的回覆。在賞金到期之前我無法來到這裏,會給你新的獎勵。 – 2964502