2024-09-27 17:54:06 发布
网友
我想用matplotlib或searborn创建一个小提琴图,其中的图是根据颜色图着色的。你知道吗
这就是我得到的:
这是我想要得到的(我在这里使用了Photoshop):
我怎样才能得到想要的情节?你知道吗
我原以为这样做会更好,但是,根据@ImportanceOfBeingErnest的评论,我猜这实际上是一条路:
from matplotlib.path import Path from matplotlib.patches import PathPatch x = [np.random.normal(loc=i, scale=1, size=(100,)) for i in range(5)] fig, ax = plt.subplots() violins = ax.violinplot(x) ymin, ymax = ax.get_ylim() xmin, xmax = ax.get_xlim() # create a numpy image to use as a gradient Nx,Ny=1,1000 imgArr = np.tile(np.linspace(0,1,Ny), (Nx,1)).T cmap = 'hsv' for violin in violins['bodies']: path = Path(violin.get_paths()[0].vertices) patch = PathPatch(path, facecolor='none', edgecolor='none') ax.add_patch(patch) img = ax.imshow(imgArr, origin="lower", extent=[xmin,xmax,ymin,ymax], aspect="auto", cmap=cmap, clip_path=patch)
我原以为这样做会更好,但是,根据@ImportanceOfBeingErnest的评论,我猜这实际上是一条路:
相关问题 更多 >
编程相关推荐