Why are all points hotpink, please? Where is a mistake. The desired result is that each point is with different colour according to the first column. Thanks
file:
fer00001.txt -30.5598 1 51183.7316 0.0 0.88884
her00034.txt -12.9113 1 50124.7613 0.0 0.93370
occ00043.txt -37.9350 1 50094.5721 0.0 0.94562
omc15564.txt -9.53485 1 51576.4297 0.0 0.56777
Code:
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
BVS, RV = np.loadtxt('file', unpack=True, usecols=[1, 5])
sp = np.loadtxt('file', unpack=True, dtype='str', usecols=[0])
kratke = [w[:3] for w in sp]
fig, ax = plt.subplots(figsize=[10,6.5])
string = [i.replace(',', ', ').replace('fer', 'FEROS').replace('her', 'HEROS').replace('occ', 'CES').replace('omc', 'RETICON') for i in kratke]
d = {'BVS': BVS, 'RV': RV, 'sp': string}
df = pd.DataFrame(data=d)
colors = {'FEROS': 'purple', 'HEROS': 'blue', 'CES': 'green', 'RETICON' : 'hotpink'}
for i in np.unique(df['sp']):
color = colors[i]
df1 = df[df['sp'] == i]
ax.scatter(df['BVS'], df['RV'], color=color, marker='o', s=6, label=i)
plt.show()
EDIT after advice
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
BVS, RV = np.loadtxt('file', unpack=True, usecols=[1, 5])
sp = np.loadtxt('file', unpack=True, dtype='str', usecols=[0])
kratke = [w[:3] for w in sp]
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=[10,6.5])
string = [i.replace(',', ', ').replace('fer', 'FEROS').replace('her', 'HEROS').replace('occ', 'CES').replace('omc', 'RETICON') for i in kratke]
d = {'BVS': BVS, 'RV': RV, 'sp': string}
df = pd.DataFrame(data=d)
colors = {'FEROS': 'purple', 'HEROS': 'blue', 'CES': 'green', 'RETICON' : 'hotpink'}
for i in np.unique(df['sp']):
color = colors[i]
df1 = df[df['sp'] == i]
ax1.scatter(df1['BVS'], df1['RV'], color=color, marker='o', s=6, label=i)
ax2.scatter(df1['BVS'][0:2], df1['RV'][0:2], color=color, marker='o', s=6, label=i)
plt.show()
Why slider does not work, please? All points are displayed again. In my original data, not points are displayed then.
