Saya memiliki kerangka data berikut yang saya coba plot,

x,y,u,v
-0.157806993154554,-0.05,0.000601310515776,0.003318849951029
-0.374687807296859,-0.35,-0.001057069515809,2.9686838388443E-05
-1,-0.323693574077183,-0.002539682900533,-0.008748378604651
-0.486242955499287,-0.35,-0.001797694480047,0.000218112021685
-0.54184300562917,-0.05,0.001513708615676,0.001884449273348
0,-0.31108016382718,5.28732780367136E-05,-0.000818025320768
-0.428046308037431,-0.35,-0.001458290731534,8.22432339191437E-05
-0.343159653530217,-0.05,0.00112508633174,0.002580288797617
-0.386254219645565,-0.35,-0.001139726256952,2.6945024728775E-05
-0.600252053226546,-0.05,0.001246933126822,0.00207519903779
-1,-0.061575842243108,-0.000705834245309,0.043682213872671
0,-0.052056831172645,0.009899478405714,-0.003894355148077
-0.903283837058102,-0.35,5.81557396799326E-05,-0.001065131276846
-0.418202966058798,-0.05,0.001158628845587,0.002409461885691
-0.809266339501268,-0.35,0.000290673458949,-2.0977109670639E-05
0,-0.066616962597653,2.92772892862558E-05,0.001737955957651
-0.090282152608,-0.35,0.00151876010932,0.001403901726007
-1,-0.173440678035212,-0.007741978392005,0.006023477762938
-1,-0.155079864747918,-0.00761691480875,0.007886063307524
-0.222728396757266,-0.35,0.000686463201419,0.000264558941126

Di mana u,v dan x,y adalah koordinat posisi dan vektor kecepatan pada titik tersebut. (set data lengkap - https://pastebin.pl/view/0f60b48e)

Saya ingin memplot data saya seperti itu (Garis kontur dan panah tidak diperlukan.) plot bidang kecepatan python pandas numpy matplotlib

0
Zizi96 12 Mei 2021, 13:57

1 menjawab

Jawaban Terbaik

Jika Anda ingin memplot bidang skalar dengan titik data tidak beraturan, Anda dapat menginterpolasi di antara titik data untuk membentuk kisi biasa, atau Anda dapat menggunakan matplotlib.pyplot.tricontour dan tricontourf untuk diinterpolasi untuk Anda isi.

Menggunakan tricontour Anda dapat mencoba:

import numpy as np
import matplotlib.pyplot as plt

x, y = box_df.x, box_df.y
  
# make scalar field
speed = np.hypot(box_df.u, box_df.v)
  
# Plotting scalar field with tricontour
plt.tricontourf(x, y, speed)
plt.title('Scalar Field')
  
# Show plot with gird
plt.grid()

enter image description here

Namun tampaknya Anda hanya memiliki data di sekitar tepi persegi panjang, jadi interpolasi ke bagian dalam persegi mungkin buruk.

enter image description here

1
user213305 12 Mei 2021, 14:07