I am trying to create a countourplot with very sparse data, without interpolation. I would like to create something like this
In other words, I would like to create a 'scatterplot/ countourplot hybrid'. Is this possible in matplotlib? If so how? Should I be using countourf() or scatterplot()? Or something else entirely?
I created an example data set below.
Many thanks!
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
In [1]:
d = {'col1': [0, 0, 0, 0, 0], 'col2': [0, 0.1, 0, 0, 0], 'col3': [0, 0.9, 0, 0, 0],
'col4': [0, 0, 0, 0.3, 0], 'col5': [0, 0, 0, 0, 0]}
df = pd.DataFrame(data=d)
df = df.replace(0, np.nan)
Out [1]:
col1 col2 col3 col4 col5
0 NaN NaN NaN NaN NaN
1 NaN 0.1 0.9 NaN NaN
2 NaN NaN NaN NaN NaN
3 NaN NaN NaN 0.3 NaN
4 NaN NaN NaN NaN NaN
plotting with contourf():
y = df.index.values
x = df.columns.values
z = df
fig1 = plt.contourf(x, y, z)