python - 如何使密集图上的所有点在 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()
解决方案
您可以使用较小的标记尺寸。问题是数据点太多以至于它们重叠导致图像变暗。
我在下面使用示例数据集对此进行了解释。左图显示默认标记大小,右图使用参数显示具有较小标记大小的相同数据ms=1
。您可以根据需要选择ms=2
等ms=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)
推荐阅读
- c - 循环中的数组没有得到正确的值
- sql-server - 存储过程 datetime 无效的列名
- java - 当您不能使用依赖注入时,缓存 ExecutorService 实例的最干净的方法是什么?
- apache-spark - 线程“JavaFX 应用程序线程”中的异常 Spark 任务不可序列化:
- python - 将来自另一个模块的所有变量导入字典 python
- python - 在 Python 中将字符串转换为字典
- python - 带循环的 Python 函数
- reactjs - React 网页和 Azure API 之间的 CORS 问题
- angular - 如何使用 Angular 在 ngStyle 中绑定数据
- javascript - 我可以在每次函数运行 JavaScript 时声明一个新变量吗