How to make a scatter plot with random values of delta_x and delta_y positions; where each point has certain frequency value(color intensity changes depending upon intensity), i.e., a certain symbols.
Example plot: (from Alberdi, et al, 2013)
How to make a scatter plot with random values of delta_x and delta_y positions; where each point has certain frequency value(color intensity changes depending upon intensity), i.e., a certain symbols.
Example plot: (from Alberdi, et al, 2013)
If I'm understanding you correctly, you're asking how to have scatter
share a color scale but have different symbols for different groups, correct?
There are a few different ways to handle this.
The key is to call scatter
multiple times (one for each different group), but pass in the same vmin
, vmax
, and cmap
arguments.
As an complete (and arguably over-complex) example of reproducing the plot above:
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()