Skip to content

Instantly share code, notes, and snippets.

@jmquintana79
Created August 2, 2024 08:57
Show Gist options
  • Save jmquintana79/01c5006109abeff91d807b2b9dc3497f to your computer and use it in GitHub Desktop.
Save jmquintana79/01c5006109abeff91d807b2b9dc3497f to your computer and use it in GitHub Desktop.
## mapplot creation of a z variable according to x/y variables, all of them, in a df
def mapplot(df:pd.DataFrame, c_x:str, c_y:str, c_z:str, title:str = '', c_map:str = "rainbow"):
# validate arguments
assert c_x in df.columns.tolist()
assert c_y in df.columns.tolist()
assert c_z in df.columns.tolist()
# initialize
import matplotlib.pyplot as plt
# collect data
x = df[c_x].values
y = df[c_y].values
z = df[c_z].values
# create colormap
plt.tricontourf(x, y, z, levels = 100, cmap = c_map)
# add color bar
plt.colorbar(label=c_z)
# labels and title
plt.xlabel(c_x)
plt.ylabel(c_y)
plt.title(title)
# show
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment