485 KiB
485 KiB
<html>
<head>
</head>
</html>
Exercise 1¶
In [13]:
# Read pile data from csv-file
df_piles = pd.read_csv('piles.csv')
# Read steel profile data from csv-file
df_profiles = pd.read_csv('steel_profiles.csv')
# Merge dataframes on "Profile" column (similar to Excel VLOOKUP)
df_merged = df_piles.merge(df_profiles, on='Profile', how='left')
In [15]:
# Display first five rows of dataframe of steel profiles
df_profiles.head()
Out[15]:
In [14]:
# Display dataframe of piles
df_piles
Out[14]:
In [16]:
# Display merged dataframe
df_merged
Out[16]:
Exercise 2¶
In [55]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Set filename for dataset of forces from an IBDAS shell element
filename = 'Crack_width_Seg7_y_direction.csv'
# Read CSV-file
df = pd.read_csv(filename, skip_blank_lines=True)
# Filter dataframe for load case and criterion for critical combination
criterion = 'max My'
df = df[df['Criterion'] == criterion]
df.head()
Out[55]:
In [56]:
# Round dataframe coordinate columns
df['x[m]'] = round(df['x[m]'], 1)
df['y[m]'] = round(df['y[m]'], 1)
# Pivot data frame data into matrix form for heatmap plotting
pivot_final = df.pivot(index='y[m]', columns='x[m]', values='w_k[mm]').sort_index(ascending=False)
# Set max allowable crack with for concrete slab for use as max value of colorbar
vmax = 0.3
# Create figure
plt.figure(figsize=(18, 8))
# Plot heatmap wiht annotation
sns.heatmap(pivot_final, annot=True, annot_kws={'size': 10}, vmax=vmax,
fmt=".2f", square=True, cbar_kws={"orientation": "horizontal"}, cmap='Reds')
# Set titles and axes labels
plt.title(f'Crack width for Segment 7, Criterion: {criterion}', fontsize=20)
plt.xlabel('Global x-coordinate [m]', fontsize=16)
plt.ylabel('Global y-coordinate [m]', fontsize=16)
Out[56]:
Some extra stuff - Conditional coloring of values¶
In [61]:
# Create figure
plt.figure(figsize=(18, 8))
# Plot heatmap wiht annotation, save axes object so it can be accessed later
ax = sns.heatmap(pivot_final, annot=True, annot_kws={'size': 10}, vmax=vmax,
fmt=".2f", square=True, cbar_kws={"orientation": "horizontal"}, cmap='Reds')
# --- Color values that exceed the max value ---
# Loop over all annotations of the axes object
for annot in ax.texts:
# Annot will now be an object which prints 'Text(x, y, w_k)'
# Extract the crack width part of the Text object and convert from string to float
wk = float(annot.get_text())
# Set all values that exceed vmax to bold and a special color
if wk > vmax:
annot.set_weight('bold')
annot.set_color('cyan')
annot.set_size(12)
plt.show()
In [ ]:
In [ ]:
In [ ]: