我想在散点图和折线图中使用客户标记。如何从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