import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from matplotlib.lines import Line2D
df = pd.read_csv('e:\phd.3\Varnehem\TrainingMLwithallteethdata.csv')
plt.rcParams['font.family'] = 'Arial'
selected_sex = ['Subadult', 'Female', 'Male']
selected_tooth_type = ['M1', 'PM', 'M2', 'M3'] # Replace with the specific tooth type/sex you want to display
filtered_df = df[(df['Sex'].isin(selected_sex)) & (df['Tooth type'].isin(selected_tooth_type))]
# Create a copy of the filtered DataFrame to avoid SettingWithCopyWarning
filtered_df = filtered_df.copy()
# Add the 'Different_Tooth' column
filtered_df['Different_Tooth'] = filtered_df['Sex'] == 'Unique_Sex'
# Replace 'Sex' with 'Individual' and 'Unique_Individual' if wanting to show individuals rather than sex
tooth_markers = {
'M1': 'o', # Circle
'PM': 's', # Square
'M2': 'v', # Inverted triangle
'M3': 'D' #Diamond
}
plt.figure(figsize=(12,8))
# Create scatterplot for each tooth type separately
#shared_palette = sns.color_palette("colorblind", n_colors=filtered_df['Individual'].nunique())
#Use the above if you want to have colors based on Individual rather than on Sex
scatter = sns.scatterplot(
x='Distance from ERJ (mm)',
y='87Sr/86Sr',
hue='Sex', # Use 'Individual' column if based on Individual
style='Tooth type',
style_order=['M1', 'PM', 'M2', 'M3'],
markers=tooth_markers, # Use different markers for teeth
data=filtered_df[~filtered_df['Different_Tooth']],
#palette=shared_palette, #Use this for Individual
s=100,
alpha=0.7
)
sns.lineplot(
x='Distance from ERJ (mm)',
y='87Sr/86Sr',
hue='Sex', # Color by individual for Figure 6
units='Individual',
estimator=None,
data=filtered_df,
#palette=shared_palette,
legend=False, # Show legend for lines
)
plt.xlim(6, 0) # x-axis to show distance from cervix
plt.ylim(0.70900, 0.73350) #Y-axis to show strontium isotopes
y_ticks = np.arange(0.70900, 0.73350, 0.00200)
plt.yticks(y_ticks, [f'{y:.4f}' for y in y_ticks])
# Add labels and title
plt.xlabel('Distance from ERJ (mm)', fontsize=14)
plt.ylabel(r'$^{87}\mathrm{Sr}/^{86}\mathrm{Sr}$', fontsize=14)
plt.title('Individual permanent enamel values', fontsize=14)
# Add minor ticks
plt.minorticks_on()
# lined region to show bioavailable ranges
# 5km range
plt.hlines(y=[0.7142, 0.7207], xmin=0, xmax=30, color='#377eb8', linestyles='--') # Horizontal lines
plt.vlines(x=[0, 30], ymin=0.7146, ymax=0.7207, color='#377eb8', linestyles='--') # Vertical lines
plt.text(5.5, 0.7150, "<5km", color='#377eb8', ha='center')
# 30 km range
plt.hlines(y=[0.7119, 0.7280], xmin=0, xmax=30, color='#984ea3', linestyles='--') # Horizontal lines
plt.vlines(x=[0, 30], ymin=0.7146, ymax=0.7207, color='#984ea3', linestyles='--') # Vertical lines
plt.text(5.5, 0.7285, "<30km", color='#984ea3', ha='center')
# Display plot
# Add the legend outside the graph (on the right side)
plt.legend(loc='upper left', bbox_to_anchor=(1, 1), frameon=False)
plt.gcf().set_dpi(1000)
plt.show
#end of code