更新散点图的标记形状 [英] Update marker shape of a scatter plot

查看:125
本文介绍了更新散点图的标记形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

散点图对象具有一种名为.set_color的方法来更新标记的颜色,并具有.set_offsets的方法来更新其位置,但是如何更新标记的形状?

解决方案

散点图返回路径集合,其中包含标记的路径.为了更改标记的形状,您需要将路径设置为新的标记路径.

对于

唯一的警告是您还需要设置标记大小,默认情况下,新标记的绘制会很大.

A scatter plot object has a method called .set_color to update the colors of the markers and .set_offsets to update their position but how can I update the marker shapes?

解决方案

A scatter plot returns a path collection, it contains the paths of the markers. In order to change the marker shape you need to set the path to the new marker path.

For built-in markers, these paths can be obtained from the MarkerStyle class. For custom markers see my SO answer here.

Example - scatter plot with dot markers later changed to plus markers:

from matplotlib import pyplot as plt
from matplotlib.markers import MarkerStyle

sp = plt.scatter([1,2],[1,2], marker='.')

new_marker = MarkerStyle("+")
sp.set_paths((new_marker.get_path(),))
sp.set_sizes([8])

plt.show()

The only caveat is that you need to set the marker size too, by default the new markers are plotted rather big.

这篇关于更新散点图的标记形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆