我想在散點圖和折線圖中使用客戶標記。如何從PNG文件製作自定義標記?如何在劇情中使用自定義標記?
12
A
回答
21
我不相信matplotlib可以自定義這樣的標記。請參閱here以瞭解您所需的自定義級別。
作爲一種替代方法,我編寫了這個使用figimage將圖像放置在線點位置的kludge。
import matplotlib.pyplot as plt
import matplotlib.image as image
# constants
dpi = 72; imageSize = (32,32)
# read in our png file
im = image.imread('smile.png')
fig = plt.figure(dpi=dpi)
ax = fig.add_subplot(111)
# plot our line with transparent markers, and markersize the size of our image
line, = ax.plot((1,2,3,4),(1,2,3,4),"bo",mfc="None",mec="None",markersize=imageSize[0] * (dpi/ 96))
# we need to make the frame transparent so the image can be seen
# only in trunk can you put the image on top of the plot, see this link:
# http://www.mail-archive.com/[email protected]/msg14534.html
ax.get_frame().set_alpha(0)
ax.set_xlim((0,5))
ax.set_ylim((0,5))
# translate point positions to pixel positions
# figimage needs pixels not points
line._transform_path()
path, affine = line._transformed_path.get_transformed_points_and_affine()
path = affine.transform_path(path)
for pixelPoint in path.vertices:
# place image at point, centering it
fig.figimage(im,pixelPoint[0]-imageSize[0]/2,pixelPoint[1]-imageSize[1]/2,origin="upper")
plt.show()
5
馬克的回答繼。我只是認爲我會添加到這一點,因爲我試圖運行這個,它做我想要的,除了實際顯示圖形上的圖標。也許matplotlib改變了一些東西。它已有 4年。
的代碼行,上面寫着:
ax.get_frame().set_alpha(0)
似乎並沒有工作,但是
ax.patch.set_alpha(0)
確實工作。
+0
http://matplotlib.org/faq/howto_faq.html – 2015-03-20 06:29:38
相關問題
- 1. 劇情旋轉標記
- 2. 如何在mapbox中自定義標記
- 3. 使用自定義標記
- 4. 如何在自定義Javascript中使用Blogger標記的值?
- 5. 如何在base.html中使用自定義模板標記
- 6. 如何在小冊子中使用自定義標記?
- 7. 核心劇情:仍然不明白如何有自定義標籤和剔
- 8. Leaflet:如何在geojson圖層上使用自定義標記?
- 9. 如何使用GoogleMaps for iOS中的自定義標記進行標記聚類?
- 10. 散景劇情標記呈現問題
- 11. 自定義標記
- 12. 在NLTK中使用自定義標籤的培訓標記器
- 13. 如何在劇情的標題內使用箭頭?
- 14. 使用gmap3自定義InfoWindow和標記
- 15. 使用GMUClusterManager的自定義標記
- 16. 使用自定義HTML標記
- 17. 如何在servlet或其他標記中調用自定義標記?
- 18. Google Analytics如何在自定義變量中標記用戶?
- 19. 劇情標籤在線路
- 20. 如何定義自由標記函數?
- 21. 如何添加自定義標記Gmap
- 22. Python劇情標籤
- 23. 如何在自定義視圖中對自定義標記進行分組?
- 24. 如何在iOS中設置自定義標記圖標與標記簇Swift
- 25. 如何在不使用陰影的情況下在自定義標記圖標周圍創建框架
- 26. 在OpenStreetMap中自定義標記
- 27. 在Android中添加自定義標記
- 28. 在PARSE中匹配自定義標記
- 29. 在Django中的自定義標記
- 30. 在導軌中自定義form_for標記
我建議這被標記爲重複:https://stackoverflow.com/questions/14324270/matplotlib-custom-marker-symbol – heisenBug 2018-02-28 22:24:32