首页 > 解决方案 > 如何使密集图上的所有点在 matplotlib 中可见?

问题描述

我正在使用这个基本代码来显示使用 matplotlib 的绘图。x 和 y 轴的列表很大。

plt.plot(r,trajectory,"k.")
plt.title("Bifurcation diagram")
plt.xlabel("R")
plt.ylabel("Xn")
plt.show()

如何更好地格式化我的绘图以查看所有细节?

通过上面的配置,我看到的是

最初的

但我想要的是看起来像这样的东西,每个点都是可见的(至少有足够高的分辨率来放大)

最后

更新:我发现迭代地调整可用参数可以产生很好的结果。使用以下答案的组合来了解参数并得出此配置。

f = plt.figure(figsize=(6,4),dpi=300)
plt.plot(r, trajectory, "k,", markersize=0.01, mew=0)
f.savefig("bifurcation_diag.png")
plt.title("Bifurcation diagram")
plt.xlabel("R")
plt.ylabel("Xn")
plt.show()

输出

标签: pythonmatplotlib

解决方案


您可以使用较小的标记尺寸。问题是数据点太多以至于它们重叠导致图像变暗。

我在下面使用示例数据集对此进行了解释。左图显示默认标记大小,右图使用参数显示具有较小标记大小的相同数据ms=1。您可以根据需要选择ms=2ms=3

import numpy as np

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))

# Default marker size
ax1.plot(np.random.randint(0, 100, 10000), np.random.randint(0, 100, 10000), 'k.')

# Smaller marker size `ms=1`
ax2.plot(np.random.randint(0, 100, 10000), np.random.randint(0, 100, 10000), 'k.', ms=1)

在此处输入图像描述


推荐阅读