-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_Design_of_Experiment.py
55 lines (39 loc) · 1.68 KB
/
plot_Design_of_Experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Set a consistent plotting style
plt.style.use('seaborn-v0_8-darkgrid')
plt.rcParams['figure.figsize'] = [10, 6] # Set a consistent figure size
file_path = r'C:\Users\Bruker\OneDrive - NTNU\Y5\Master_thesis\Idun\Design_of_Experiment\LHC_cat_1000.csv'
# Read the CSV file into a DataFrame
data = pd.read_csv(file_path)
# Display the first few rows to understand the data structure
print("Data Head:\n", data.head())
# Display the data types to ensure they are as expected
print("\nData Types:\n", data.dtypes)
temperature_column = 'Temperature'
class_column = 'Class'
# Convert temperature to numeric
data[temperature_column] = pd.to_numeric(data[temperature_column], errors='coerce')
# Convert class to string to map properly
data[class_column] = data[class_column].astype(str)
# Map the class values to concentration labels
class_mapping = {
'1.0': '100%',
'2.0': '75%',
'3.0': '66%'
}
# Apply the mapping to the class column
data['Concentration'] = data[class_column].map(class_mapping)
# Check the mapping results
print("\nMapped Concentration Column:\n", data['Concentration'].head())
# Ensure concentration is a categorical type with the right order
data['Concentration'] = pd.Categorical(data['Concentration'], categories=['100%', '75%', '66%'], ordered=True)
# Plot using seaborn
plt.figure(figsize=(10, 6))
sns.swarmplot(x='Concentration', y=temperature_column, data=data, palette={'100%': 'red', '75%': 'green', '66%': 'blue'})
plt.xlabel('Li Concentration')
plt.ylabel('Temperature (K)')
plt.grid(True)
plt.savefig("LHC_1000_swarmplot.png")
plt.show()