python - matplotlib可视化-正负比例图
问题描述
我正在尝试制作与下面相同的图表,并想知道 matplotlib 是否有类似的图表来制作它。
下图是R包中STM主题模型的结果
我在 Python 中使用 DMR 有概率值:
array([[0.07204196, 0.04238116],
[0.04518877, 0.30546978],
[0.0587892 , 0.19870868],
[0.16710107, 0.07182639],
[0.128209 , 0.02422131],
[0.15264449, 0.07237352],
[0.2250081 , 0.06986096],
[0.1337716 , 0.10750801],
[0.01197221, 0.06736039],
[0.00527367, 0.04028973]], dtype=float32)
这些是结果,左边是否定词,右边是肯定词
负正比例图示例:
解决方案
我不确定问题的关键部分是什么。也就是说,您是否对基于类别标记各个点更感兴趣,或者您是否更关心带有一条线的唯一圆。使用提供的数组,数据代表的内容有点令人困惑。
我假设每个子列表代表一个类别。考虑到这一点,我所做的是为值的差异创建一个单独的列 (delta),然后将它们与索引进行对比。
# New column (delta) with styling
df['delta'] = df[0]-df[1]
col = np.where(df.delta>0,'g',np.where(df.index<0,'b','r'))
fig, ax = plt.subplots(figsize =(10,7))
# Style it up a bit
plt.title('Differnece in Topic Proportion (Negative vs Positive)')
plt.xlabel('Net Review Score')
plt.ylabel('Index Number')
plt.tight_layout()
plt.savefig("Evolution of rapport of polarisation - (Aluminium).png")
plt.scatter(df['delta'], df.index, s=None, c=col, marker=None, linewidth=2)
plt.axvline(x = 0, color = 'b', label = 'axvline - full height', linestyle="--" )
这给出了一个结果:
推荐阅读
- java - JAX-RS 可变路径深度
- swagger - 如何创建可导入 Azure API 管理门户的 Web API
- javascript - 使用 D3 确定选择/选项
- android - 使用 lambda 创建回调
- python - 为什么在天文学中从地球坐标转换到银河中心坐标不能保持距离?
- c++ - unsigned int 与 unsigned long 都是 32 位的,但我不能在不强制转换的情况下混合它们......为什么?
- python-3.x - 尽管采用随机数据,拟合优度始终为零?
- javascript - 当我在页面上和页面外有链接时,如何使用 Scrollspy?
- swift - 附加到 AVAssetWriterInputPixelBufferAdaptor 失败
- sqlite - System.data.Sqlite:无论使用 Query 还是 NonQuery,都返回受影响的行数