Matplotlib散点图/轮廓混合图

时间:2019-01-30 10:16:29

标签: python matplotlib scatter-plot contourf

我试图创建一个非常稀疏的数据而没有插值的countourplot。我想创建这样的东西

enter image description here

换句话说,我想创建一个“散点图/ countourplot混合”。在matplotlib中可能吗?如果可以,怎么办?我应该使用countourf()还是scatterplot()?还是完全其他?

我在下面创建了一个示例数据集。

非常感谢!

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

使用轮廓f()进行绘图:

y = df.index.values
x = df.columns.values
z = df
fig1 = plt.contourf(x, y, z)

0 个答案:

没有答案
相关问题