-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIDA_Plot.py
More file actions
80 lines (65 loc) · 3.24 KB
/
Copy pathIDA_Plot.py
File metadata and controls
80 lines (65 loc) · 3.24 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.lines import Line2D
plt.rcParams['font.family'] = 'Times New Roman'
# Load the dataset — using raw string (r'...') to avoid backslash escape issues
df = pd.read_csv(r'E:\PYTHON_WORKSPACE\Vulnerability-Assessment-of-an-existing-Pre-Code-Building-in-Nepal-main\Building_Bare_Kabin\IDA Data.csv')
# Strip whitespace from all column names to fix hidden spacing issues
df.columns = df.columns.str.strip()
# ── DIAGNOSTIC: print actual column names so you can verify them ──────────────
print("Columns in your CSV:")
for col in df.columns.tolist():
print(f" {repr(col)}")
print()
# ─────────────────────────────────────────────────────────────────────────────
# Unique RSNs (taken from the column with the most data to ensure we catch all)
unique_rsns = df['RSN Steel Angle'].unique()
configs = {
'Bare': {'rsn': 'RSN Bare', 'pga': 'PGA (g) Bare', 'midr': 'MIDR (%) Bare', 'color': 'tab:blue', 'label': 'Bare'},
'Steel Angle': {'rsn': 'RSN Steel Angle', 'pga': 'PGA (g) Steel Angle', 'midr': 'MIDR (%) Steel Angle', 'color': 'tab:orange', 'label': 'Steel Angle Retrofit'},
}
# Validate that all expected columns exist before plotting
missing = []
for name, config in configs.items():
for key in ['rsn', 'pga', 'midr']:
col = config[key]
if col not in df.columns:
missing.append(f"[{name}] '{col}'")
if missing:
print("ERROR — The following expected columns were NOT found in the CSV:")
for m in missing:
print(f" {m}")
print("\nCheck the diagnostic output above and update the column names in 'configs' to match exactly.")
raise SystemExit(1)
fig, ax = plt.subplots(figsize=(10, 7))
# 1. Plot individual RSN curves
for name, config in configs.items():
first = True # Helper to avoid duplicate legend entries
for rsn in unique_rsns:
# Filter each case by its own RSN column to handle misaligned rows
data = df[df[config['rsn']] == rsn][[config['pga'], config['midr']]].dropna().sort_values(by=config['pga'])
if not data.empty:
ax.plot(data[config['pga']], data[config['midr']],
color=config['color'], alpha=0.8, linewidth=1.2,
label=config['label'] if first else "")
first = False
# 2. Add Horizontal limit lines and labels (IO, LS, CP)
y_limits = {1: 'IO', 2: 'LS', 4: 'CP'}
for y, text in y_limits.items():
ax.axhline(y, color='brown', linestyle='--', linewidth=1.2)
ax.text(0.99, y + 0.05, text, transform=ax.get_yaxis_transform(),
color='black', fontsize=14, ha='right', va='bottom')
# 3. Add Vertical line (Design PGA reference)
ax.axvline(0.35, color='tab:red', linestyle='--', linewidth=1.2)
# Formatting
ax.set_xlabel('PGA (g)', fontsize=17)
ax.set_ylabel('MIDR (%)', fontsize=17)
ax.tick_params(direction='in', top=True, right=True, labelsize=15)
ax.set_title('Incremental Dynamic Analysis (IDA)', fontsize=18)
ax.legend(loc='lower right', fontsize=12)
ax.set_xlim(left=0)
ax.set_ylim(bottom=0)
ax.grid(False)
plt.tight_layout()
plt.show()