我想建立一个图,看起来像这样,-对于每个点,我有一个单一的值,有一个最大值,到达边界。所有我能找到的是如何有hexbin在散点图与seaborn或类似的-任何想法,有一些现成的解决方案,也许或者我需要通过它编码我的方式?
nhn9ugyo1#
您可以使用tripcolor来显示6个阴影三角形。缩放外部向量可以调整三角形以显示所需的比例。
tripcolor
import numpy as np import matplotlib.pyplot as plt import matplotlib.tri as tri proportions = [0.6, 0.75, 0.8, 0.9, 0.7, 0.8] labels = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta'] N = len(proportions) proportions = np.append(proportions, 1) theta = np.linspace(0, 2 * np.pi, N, endpoint=False) x = np.append(np.sin(theta), 0) y = np.append(np.cos(theta), 0) triangles = [[N, i, (i + 1) % N] for i in range(N)] triang_backgr = tri.Triangulation(x, y, triangles) triang_foregr = tri.Triangulation(x * proportions, y * proportions, triangles) cmap = plt.cm.rainbow_r # or plt.cm.hsv ? colors = np.linspace(0, 1, N + 1) plt.tripcolor(triang_backgr, colors, cmap=cmap, shading='gouraud', alpha=0.4) plt.tripcolor(triang_foregr, colors, cmap=cmap, shading='gouraud', alpha=0.8) plt.triplot(triang_backgr, color='white', lw=2) for label, color, xi, yi in zip(labels, colors, x, y): plt.text(xi * 1.05, yi * 1.05, label, # color=cmap(color), ha='left' if xi > 0.1 else 'right' if xi < -0.1 else 'center', va='bottom' if yi > 0.1 else 'top' if yi < -0.1 else 'center') plt.axis('off') plt.gca().set_aspect('equal') plt.show()
该代码允许不同数量的三角形。下面是5个或6个三角形的例子:
1条答案
按热度按时间nhn9ugyo1#
您可以使用
tripcolor
来显示6个阴影三角形。缩放外部向量可以调整三角形以显示所需的比例。该代码允许不同数量的三角形。下面是5个或6个三角形的例子: