如何在matplotlib中绘制上三角矩阵的轮廓?

如何在matplotlib中绘制上三角矩阵的轮廓?,matplotlib,matrix,contour,triangular,Matplotlib,Matrix,Contour,Triangular,我想在散点图上为z=0.35的数据添加一个等高线图 以下是我的数据: X Y Z 0.100 0.500 0.455 0.100 1.000 0.453 0.100 1.500 0.451 0.100 2.000 0.449 0.100 3.000 0.448 0

我想在散点图上为z=0.35的数据添加一个等高线图

以下是我的数据:

 X               Y         Z
0.100        0.500        0.455     
0.100        1.000        0.453     
0.100        1.500        0.451     
0.100        2.000        0.449     
0.100        3.000        0.448     
0.100        4.000        0.445     
0.100        5.000        0.442     
0.100        6.000        0.437     
0.100        7.000        0.425     
0.100        8.000        0.411     
0.100        9.000        0.398     
0.100        10.000       0.383     
0.100        10.500       0.375     
0.100        11.000       0.364     
0.100        11.300       0.357     
0.100        11.500       0.349     
0.100        11.800       0.336     
0.100        12.000       0.324     
0.100        12.300       0.299     
0.100        12.500       0.269     
0.500        1.000        0.452     
0.500        1.500        0.450     
0.500        2.000        0.449     
0.500        3.000        0.447     
0.500        4.000        0.445     
0.500        5.000        0.442     
0.500        6.000        0.437     
0.500        7.000        0.424     
0.500        8.000        0.410     
0.500        9.000        0.396     
0.500        10.000       0.382     
0.500        10.500       0.373     
0.500        11.000       0.362     
0.500        11.300       0.355     
0.500        11.500       0.347     
0.500        11.800       0.334     
0.500        12.000       0.322     
0.500        12.300       0.297     
0.500        12.500       0.267     
1.000        1.500        0.448     
1.000        2.000        0.448     
1.000        3.000        0.446     
1.000        4.000        0.444     
1.000        5.000        0.441     
1.000        6.000        0.436     
1.000        7.000        0.422     
1.000        8.000        0.407     
1.000        9.000        0.394     
1.000        10.000       0.379     
1.000        10.500       0.371     
1.000        11.000       0.360     
1.000        11.300       0.352     
1.000        11.500       0.345     
1.000        11.800       0.330     
1.000        12.000       0.319     
1.000        12.300       0.293     
1.000        12.500       0.263     
1.500        2.000        0.447     
1.500        3.000        0.445     
1.500        4.000        0.442     
1.500        5.000        0.439     
1.500        6.000        0.434     
1.500        7.000        0.420     
1.500        8.000        0.405     
1.500        9.000        0.392     
1.500        10.000       0.377     
1.500        10.500       0.368     
1.500        11.000       0.357     
1.500        11.300       0.350     
1.500        11.500       0.342     
1.500        11.800       0.328     
1.500        12.000       0.316     
1.500        12.300       0.290     
2.000        3.000        0.443     
2.000        4.000        0.441     
2.000        5.000        0.439     
2.000        6.000        0.433     
2.000        7.000        0.418     
2.000        8.000        0.403     
2.000        9.000        0.388     
2.000        10.000       0.374     
2.000        10.500       0.365     
2.000        11.000       0.354     
2.000        11.300       0.347     
2.000        11.500       0.339     
2.000        11.800       0.325     
2.000        12.000       0.313     
2.000        12.300       0.287     
2.000        12.500       0.256     
3.000        4.000        0.439     
3.000        5.000        0.437     
3.000        6.000        0.431     
3.000        7.000        0.413     
3.000        8.000        0.397     
3.000        9.000        0.382     
3.000        10.000       0.368     
3.000        10.500       0.359     
3.000        11.000       0.348     
3.000        11.300       0.341     
3.000        11.500       0.333     
3.000        11.800       0.318     
3.000        12.000       0.306     
3.000        12.300       0.280     
3.000        12.500       0.248     
4.000        5.000        0.435     
4.000        6.000        0.427     
4.000        7.000        0.406     
4.000        8.000        0.388     
4.000        9.000        0.375     
4.000        10.000       0.360     
4.000        10.500       0.351     
4.000        11.000       0.340     
4.000        11.300       0.333     
4.000        11.500       0.325     
4.000        11.800       0.310     
4.000        12.000       0.298     
4.000        12.300       0.270     
4.000        12.500       0.239     
5.000        6.000        0.418     
5.000        7.000        0.392     
5.000        8.000        0.375     
5.000        9.000        0.363     
5.000        10.000       0.350     
5.000        10.500       0.341     
5.000        11.000       0.330     
5.000        11.300       0.324     
5.000        11.500       0.315     
5.000        11.800       0.300     
5.000        12.000       0.288     
5.000        12.300       0.260     
5.000        12.500       0.228     
6.000        7.000        0.368     
6.000        8.000        0.356     
6.000        9.000        0.347     
6.000        10.000       0.337     
6.000        10.500       0.329     
6.000        11.000       0.318     
6.000        11.300       0.313     
6.000        11.500       0.304     
6.000        11.800       0.289     
6.000        12.000       0.276     
6.000        12.300       0.247     
6.000        12.500       0.214     
7.000        8.000        0.346     
7.000        9.000        0.339     
7.000        10.000       0.329     
7.000        10.500       0.322     
7.000        11.000       0.311     
7.000        11.300       0.305     
7.000        11.500       0.296     
7.000        11.800       0.280     
7.000        12.000       0.267     
7.000        12.300       0.237     
7.000        12.500       0.202     
8.000        9.000        0.332     
8.000        10.000       0.322     
8.000        10.500       0.315     
8.000        11.000       0.303     
8.000        11.300       0.297     
8.000        11.500       0.287     
8.000        11.800       0.270     
8.000        12.000       0.256     
8.000        12.300       0.224     
8.000        12.500       0.188     
9.000        10.000       0.314     
9.000        10.500       0.305     
9.000        11.000       0.293     
9.000        11.300       0.287     
9.000        11.500       0.276     
9.000        11.800       0.257     
9.000        12.000       0.242     
9.000        12.300       0.208     
9.000        12.500       0.170     
10.000       10.500       0.292     
10.000       11.000       0.277     
10.000       11.300       0.273     
10.000       11.500       0.259     
10.000       11.800       0.236     
10.000       12.000       0.220     
10.000       12.300       0.182     
10.000       12.500       0.143     
10.500       11.000       0.264     
10.500       11.300       0.264     
10.500       11.500       0.247     
10.500       11.800       0.221     
10.500       12.000       0.203     
10.500       12.300       0.164     
10.500       12.500       0.123     
11.000       11.300       0.264     
11.000       11.500       0.235     
11.000       11.800       0.202     
11.000       12.000       0.182     
11.000       12.300       0.140     
11.000       12.500       0.098     
11.300       11.500       0.190     
11.300       11.800       0.165     
11.300       12.000       0.150     
11.300       12.300       0.111     
11.300       12.500       0.072     
11.500       11.800       0.150     
11.500       12.000       0.136     
11.500       12.300       0.096     
11.500       12.500       0.058     
11.800       12.000       0.118     
11.800       12.300       0.074     
11.800       12.500       0.036     

我在解释你的问题时有点困难,但我想你需要一条表示
z=0.35
的等高线,绘制在散点图上。为此,首先需要将Z数据插值到常规XY栅格上(例如,使用)。然后,可以绘制插值数据的轮廓:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import griddata

# Read the input data
data = pd.read_csv("data.csv", names=("x", "y", "z"), delim_whitespace=True, header=0)

# Create interpolation grid
xi = np.linspace(data["x"].min(), data["x"].max(), 100)
yi = np.linspace(data["y"].min(), data["y"].max(), 100)
Xi, Yi = np.meshgrid(xi, yi)
points = np.array([data["x"], data["y"]]).T
outpoints = np.array([Xi, Yi]).T

# Interpolate z-values on grid
zi = griddata(points=points, values=data["z"], xi=outpoints, method="cubic")

# Plot contour line at z=0.35
CS = plt.contour(xi, yi, zi.T, levels=[0.35], colors="k")
plt.clabel(CS)

# Plot scatter on top of contour
plt.scatter(data["x"], data["y"], c=data["z"], cmap="Blues", s=5)
plt.colorbar()
plt.show()
结果:


你的尝试在哪里?