gpt4 book ai didi

python - 如何制作不同大小、颜色、位置的散点图?

转载 作者:太空宇宙 更新时间:2023-11-04 05:44:43 24 4
gpt4 key购买 nike

如何使用 delta_x 和 delta_y 位置的随机值制作散点图;其中每个点都有一定的频率值(颜色强度根据强度变化),即一定的符号。

示例图:(来自 Alberdi, et al, 2013 )

enter image description here

最佳答案

如果我没理解错的话,你是在问如何让 scatter 共享一个色标,但对不同的组使用不同的符号,对吗?

有几种不同的方法来处理这个问题。

关键是多次调用scatter(每个不同的组调用一次),但传入相同的vminvmaxcmap 参数。

作为重现上述情节的完整(并且可以说过于复杂)示例:

import numpy as np
import matplotlib.pyplot as plt

# Generate data
freq_groups = [1.7, 2.3, 5.0, 8.4]
num = 50
x = np.random.normal(0, 0.5, num)
y = np.random.normal(0.2, 0.5, num)
year = 9 * np.random.random(num) + 1993.5
frequencies = np.random.choice(freq_groups, num)

symbols = ['o', '^', 's', 'd']

# Plot data
fig, ax = plt.subplots(figsize=(8, 9))
for freq, marker in zip(freq_groups, symbols):
mask = np.isclose(freq, frequencies)
scat = ax.scatter(x[mask], y[mask], c=year[mask], s=100, marker=marker,
cmap='jet_r', vmin=year.min(), vmax=year.max(),
label='{:0.1f} GHz'.format(freq), color='black')

ax.legend(loc='upper left', scatterpoints=1)
ax.set(xlabel='Relative RA (mas)', ylabel='Relative Dec (mas)')
ax.invert_xaxis()
cbar = fig.colorbar(scat, orientation='horizontal')
cbar.set_label('Epoch (year)')
cbar.formatter.useOffset = False
cbar.update_ticks()
fig.tight_layout()

plt.show()

enter image description here

关于python - 如何制作不同大小、颜色、位置的散点图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32720042/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com