我感兴趣的是构建向日葵散点图(如http://www.jstatsoft.org/v08/i03/paper PDF链接中所描述的)。在我写我自己的实现之前,有人知道一个现有的实现吗?我知道Stata和R中的函数,但我正在寻找matplotlib中的函数。
谢谢。
发布于 2014-03-06 01:37:37
我不知道任何matplotlib实现,但这并不难。在这里,我让hexbin做计数,然后遍历每个单元,并添加适当数目的花瓣:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import colors
np.random.seed(0)
n = 2000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
cmap = colors.ListedColormap(['white', 'yellow', 'orange'])
hb = plt.hexbin(x,y, bins='log', cmap=cmap, gridsize=20, edgecolor='gray')
plt.axis([-2, 2, -12, 12])
plt.title("sunflower plot")
counts = hb.get_array()
coords = hb.get_offsets()
for i, count in enumerate(counts):
x, y = coords[i,:]
count = int(10**count)
if count>3 and count<=12:
n = count // 1
if n>1:
plt.plot([x], [y], 'k.')
plt.plot([x], [y], marker=(n, 2), color='k', markersize=18)
if count>12:
n = count // 5
if n>1:
plt.plot([x], [y], 'k.')
plt.plot([x], [y], marker=(n, 2), color='k', markersize=18)
plt.show()这里黄色是1花瓣= 1,橙色1花瓣= 5。
在这里,一个明显的改进之处是使用彩色地图。例如,您是要预置颜色边界还是从数据中计算它们等等?在这里,我只是简单地说明了一下:我使用bins='log'只是为了为我使用的特定样本获得黄色和橙色单元格之间的合理比例;我还硬编码白色、黄色和橙色单元(3和12)之间的边界。
能够使用元组指定matplotlib中的标记特征,因此可以很容易地绘制所有不同的花瓣数。
https://stackoverflow.com/questions/22162557
复制相似问题