Skip to content

Instantly share code, notes, and snippets.

@Chrisvandr
Created April 19, 2018 07:25
Show Gist options
  • Save Chrisvandr/ce0cb1d2c3832ec1d6f98d4ad3e8c23a to your computer and use it in GitHub Desktop.
Save Chrisvandr/ce0cb1d2c3832ec1d6f98d4ad3e8c23a to your computer and use it in GitHub Desktop.
Display UDI data in heatmap
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import getpass
UserName = getpass.getuser()
if UserName == 'cvdronke':
path_to_file = 'C:/Users/' + UserName
else:
path_to_file = 'D:'
df = pd.read_table(path_to_file + '/OneDrive - BuroHappold/SF000004_A.txt',
skiprows=15, # skiprows
delim_whitespace=True,
header=None)
df = df[:-1] # remove avg. at end of file
df_xyz = df.iloc[:, :3] # get x,y,z columns
df_UDI = df.iloc[:, 3:] # get UDI columns
df_UDI.columns = ['UDI_' + str(i) for i in range(len(df_UDI.columns))]
df_xyz.columns = ['x', 'y', 'z']
df_xyz.x = df_xyz.x.str.strip('()')
df_xyz.z = df_xyz.z.str.strip('()')
df = pd.concat([df_xyz.x, df_xyz.y, df_UDI.UDI_3], axis=1) # get UDI_#
df.columns = ['x', 'y', 'z']
df = df.apply(pd.to_numeric)
df = df.pivot(index='x', columns='y', values='z')
sns.heatmap(df,
annot=False,
cbar=False,
yticklabels=False,
xticklabels=False,
fmt='.0f',
annot_kws={"size": 7},
cmap="Blues_r",
linewidth=0.0,
rasterized=True)
plt.savefig(path_to_file + '/OneDrive - BuroHappold/UDI_annot.png', dpi=500, transparent=True, bbox_inches='tight')
plt.show()
@AntoineDao
Copy link

Nice quick and easy! I like it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment