簡體   English   中英

如何繪制使用三列向量的顏色圖?

[英]How do I plot a color plot for using three column vectors?

我有三個向量,X、Y 和 Coc。 X 和 Y 是以米為單位的位置。 我想使用 Python 在顏色圖中可視化 Coc。

我想用下面的代碼繪制顏色圖

import pandas as pd
import matplotlib.pyplot as plt
    X=pd.read_csv('X.csv')
    Y=pd.read_csv('Y.csv')
    Coc=pd.read_csv('Coc.csv')
    
    
plt.pcolor(X,Y,Coc*1e6, cmap='jet');
plt.clim((1e-17, 1e-1));
plt.xlabel('x (metres)');
plt.ylabel('y (metres)');
cb1=plt.colorbar();

plt.show()

但我得到一個空圖。

我做錯了什么,或者有沒有其他方法可以可視化數據。

數據 X、Y 和 Coc 在 url 中。

https://drive.google.com/folderview?id=1w9f-wTlpgyUYBveZNeZvdcRrMgFR9jKB

您有 222 個條目,但只有 6 個不同的xy對。 您無法從此類數據創建pcolor圖。

要繪制對應於每個xy對的Coc分布,您可以遍歷 6 對並根據相應的Coc值創建kdeplot 更改圖例的一種簡單方法是使用plt.legend(new_labels, title='Locations:')

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns

X = np.array([754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19, 754.285, 755.062, 756.754, 758.071, 758.195, 759.19])
Y = np.array([569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993, 569.503, 570.785, 571.896, 572.669, 574.231, 576.993])
Coc = np.array([3.96e-15,2.39e-15,8.5e-15,2.83e-14,7.59e-15,2.0287e-01,1.1584e-02,2.1402e-01,3.5672e-02,5.2448e-02,1.2968e-02,3.2069e-02,2.267e-02,2.553e-01,4.1874e-02,5.9223e-01,1.9305e-01,4.3572e-02,4.9312e-02,2.9767e-01,2.8906e-02,3.67e-14,1.4846e-02,9.2954e-03,1.e-14,3.73e-02,5.67e-15,5.92e-15,7.62e-15,1.3594e-02,2.3187e-02,1.5313e-02,2.6313e-02,1.2019e-02,5.3779e-02,2.0352e-02,8.21e-15,1.2439e-01,1.08e-14,8.32e-15,1.86e-14,1.13e-14,1.97e-14,8.75e-15,4.33e-15,1.6688e-02,1.3375e-02,7.7849e-03,1.5341e-02,6.44e-15,9.18e-15,5.3385e-02,3.4455e-02,2.3291e-02,2.7082e-02,3.1913e-02,1.24e-14,1.89e-14,4.67e-15,5.09e-15,1.08e-14,1.75e-14,1.12e-14,4.14e-15,3.54e-15,1.84e-15,1.315e-02,2.2633e-02,3.1406e-02,2.677e-02,3.61e-15,1.2997e-02,6.59e-15,2.62e-14,8.5e-15,1.2e-14,4.29e-15,5.06e-15,1.3807e-02,4.4542e-02,5.5308e-02,1.0526e-01,1.9305e-02,1.9241e-02,1.2328e-02,1.8143e-01,6.5041e-02,1.7483e-02,1.0189e-02,6.4138e-03,2.8158e-02,9.6417e-02,3.8939e-02,1.8071e-02,1.07e-14,4.7207e-02,9.424e-03,1.6424e-02,1.5549e-02,3.56e-15,1.2974e-02,1.4416e-02,2.81e-14,1.15e-14,9.34e-15,7.5394e-02,5.41e-15,1.3e-15,1.68e-14,6.8171e-02,3.7142e-01,1.29e-14,4.04e-15,3.6949e-02,8.29e-14,1.1353e-01,1.0511e-01,6.9931e-02,2.2165e-02,3.99e-15,7.5611e-02,7.2137e-02,6.5534e-02,1.1801e-01,7.3289e-02,1.2758e-01,9.65e-14,6.57e-14,4.06e-14,1.1855e-01,1.8555e-01,7.8953e-02,3.27e-14,1.34e-13,7.62e-14,4.5127e-01,2.15e-14,1.87e-14,3.9084e-02,5.8303e-02,2.5415e-02,1.1801e-01,1.0993e-02,2.8583e-02,8.5474e-02,1.4232e-01,4.5611e-03,5.7911e-02,2.3238e-02,5.4378e-02,4.17e-14,1.9012e-01,5.8091e-02,1.3003e-01,7.9366e-02,6.4835e-02,4.0271e-02,3.1583e-02,2.5052e-02,5.5835e-01,5.2339e-02,9.7333e-03,6.276e-03,3.6937e-02,2.5363e-02,1.2715e-02,2.869e-02,1.6557e-02,4.23e-14,7.85e-14,3.75e-15,3.88e-14,9.77e-14,2.4679e-01,2.63e-14,8.7e-15,3.8667e-02,2.28e-14,7.56e-15,1.6e-15,1.52e-14,1.65e-14,2.73e-14,2.72e-14,8.5802e-03,2.82e-14,1.86e-14,1.96e-14,1.1001e-01,3.32e-14,1.0628e-02,1.6313e-01,3.4518e-02,2.9333e-01,2.7339e-01,3.125e-01,2.7778e-01,6.3057e-01,2.e-14,3.1143e-02,1.9824e-02,7.4301e-02,1.43e-02,1.8405e-01,5.58e-14,1.45e-14,3.46e-15,1.36e-14,1.6e-14,3.65e-15,1.1232e-01,5.6927e-02,2.0913e-01,1.2839e-01,7.7758e-02,6.0391e-02,1.55e-16,1.0728e-02,1.4741e-02,1.1801e-02,4.2257e-03,9.5423e-03])

for x in np.unique(X):
    y = Y[X==x][0]
    sns.kdeplot(Coc[X==x], label=f'X={x} Y={y}')
legend_labels = ['New Orleans', 'Cartagena', 'Vienna', 'Pretoria', 'Beijing', 'Brisbane']
plt.legend(legend_labels)
plt.show()

結果圖

另一種方法是對屬於每個xy對的所有Coc值進行排序:

for i, x in enumerate(np.unique(X)):
    y = Y[X==x][0]
    plt.plot(np.sort(Coc[X==x])[::-1], label=f'X={x} Y={y}')
plt.legend()
plt.margins(x=0.01)
plt.xlabel('<--------------------- highest Coc values                  lowest Coc values --------------------->')
plt.ylabel('Coc')

對值進行排序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM