简体   繁体   English

更新散点图的标记大小

[英]Update marker sizes of a scatter plot

A scatter plot object has a method called .set_array to update the colours of the markers and .set_offsets to update their position but how can I update the marker sizes? 散点图对象具有一种名为.set_array的方法来更新标记的颜色,而具有.set_offsets以更新其位置,但是如何更新标记的大小?

I need this for fast real time plotting. 我需要它来进行快速实时绘图。

Yes it is doable, with using a magic method ( _size ). 是的,通过使用魔术方法( _size ),它是可行的。 Use it with caution, as it may become broken in future releases: 请谨慎使用,因为它在将来的版本中可能会损坏:

from matplotlib import pyplot as plt
import numpy as np

x, y=range(10), range(10)
sca=plt.scatter(x,y)
raw_input()
sca._sizes=(5+np.arange(10))*10 #you can set you markers to different sizes
plt.draw()

在此处输入图片说明

The method to update the sizes of the scatter points is called .set_sizes() 更新散点大小的方法称为.set_sizes()

scat = plt.scatter(x,y)
scat.set_sizes(sizes)

where sizes must be an array or list of same length as x and y . 其中sizes必须是与xy相同长度的数组或列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM