python小提琴图

编程入门 行业动态 更新时间:2024-10-08 13:29:21
本文介绍了python小提琴图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在一张图中创建10个小提琴图.我看了很多像这样的例子:小提琴图matplotlib ,这说明了我的想法喜欢在结尾处.

I want to create 10 violin plots but within one diagram. I looked at many examples like this one: Violin plot matplotlib, what shows what I would like to have at the end.

但是我不知道如何使它适应真实的数据集.它们都只生成一些正态分布的随机数据. 我的数据格式为D [10,730],如果我尝试通过上面的链接使用以下方法进行改编: 例如:

But I did not know how to adapt it to a real data set. They all just generate some random data which is normal distributed. I have data in form D[10,730] and if I try to adapt it from the link above with : example:

axes[0].violinplot(all_data,showmeans=False,showmedians=True)

我的代码:

axes[0].violinplot(D,showmeans=False,showmedians=True)

它不起作用. 它应该并行打印10个小提琴图(D的第一维).

it do not work. It should print 10 violin plot in parallel (first dimension of D).

那么我的数据看起来如何才能获得相同类型的小提琴图?

So how do my data need to look like to get the same type of violin plot?

推荐答案

您只需要转置数据数组D.

You just need to transpose your data array D.

axes[0].violinplot(D.T,showmeans=False,showmedians=True)

这似乎是matplotlib中的一个小错误.对于一维数组和2D数组,以不一致的方式处理轴.

This appears to be a small bug in matplotlib. The axes are treated in a non-consistent manner for a list of 1D arrays and a 2D array.

import numpy as np import matplotlib.pyplot as plt n_datasets = 10 n_samples = 730 data = np.random.randn(n_datasets,n_samples) fig, axes = plt.subplots(1,3) # matplotlib/examples/statistics/boxplot_vs_violin_demo.html axes[0].violinplot([d for d in data]) # should be equivalent to: axes[1].violinplot(data) # is actually equivalent to axes[2].violinplot(data.T)

您应该提交错误报告.

更多推荐

python小提琴图

本文发布于:2023-07-18 08:16:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小提琴   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!