ValueError: массив z не должен содержать не конечных значений в триангуляции - PullRequest
0 голосов
/ 19 апреля 2020

Я пытаюсь обрезать контурный график, используя метод триангуляции Делоне. У меня есть входные данные x, y, z, импортированные из таблицы Excels. Данные z представлены в виде массива numpy, и я показал это ниже.

Любая помощь будет принята с благодарностью.

import matplotlib.pyplot as plt
import matplotlib.tri as tri
import numpy as np
import pandas as pd

# Import data
Input_data_dataframe = pd.read_excel(
    r'C:\Users\import_file.xlsx')

columns = ['X', 'Y','Delay']

df = Input_data_dataframe[columns]
x = df['X'].to_numpy()
y = df['Y'].to_numpy()
z = df['Delay'].to_numpy()


triang1 = tri.Triangulation(x, y) # Delaunay triangulation of all points.
triang2 = tri.Triangulation(x, y) # Delaunay triangulation of all points.
triang3 = tri.Triangulation(x, y) # Delaunay triangulation of all points.

def apply_mask(triang, alpha=0.4):
    # Mask triangles with sidelength bigger some alpha
    triangles = triang.triangles
    # Mask off unwanted triangles.
    xtri = x[triangles] - np.roll(x[triangles], 1, axis=1)
    ytri = y[triangles] - np.roll(y[triangles], 1, axis=1)
    maxi = np.max(np.sqrt(xtri**2 + ytri**2), axis=1)
    # apply masking
    triang.set_mask(maxi > alpha)

apply_mask(triang2, alpha=0.5)
apply_mask(triang3, alpha=0.7)

fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(9,3))

ax1.tricontourf(triang1, z,  cmap="Oranges")
ax1.scatter(x,y, s=3, color="k")

ax2.tricontourf(triang2, z,  cmap="Oranges")
ax2.scatter(x,y, s=3, color="k")

ax3.tricontourf(triang3, z,  cmap="Oranges")
ax3.scatter(x,y, s=3, color="k")

ax1.set_title("tricontourf without mask")
ax2.set_title("with mask (alpha=0.5)")
ax3.set_title("with mask (alpha=0.7)")

for ax in (ax1, ax2, ax3):
    ax.set(xlim=(0,1), ylim=(0,1), aspect="equal")

plt.show()

Я получаю следующую ошибку 'ValueError: массив z не должен содержать бесконечные значения в рамках триангуляции'

значения z, как показано ниже:

[13041 12989 12943 12893 12844 12795 12746 12696 12648 12599 12549 12500
 12451 12404 12354 12305 12256 12207 12157 12108 12059 12022 11960 11911
 11862 11813 11764 11714 11666 13015 12966 12916 12867 12818 12769 12719
 12670 12621 12572 12523 12473 12424 12385 12326 12277 12228 12179 12129
 12080 12035 11982 11945 11883 11834 11785 11736 11698 11637 11571 11500
 11421 11334 11251 11157 11062 10955 10873 10779 10684 10590 10507 10407
 10304 10171 10069  9955  9840  9722  9602  9494  9361  9240  9126  8999
  8889  8766  8635  8515  8412  8286  8163  8041  7909  7816  7673  7545
  7422  7302  7188  7059  6937  6814  6681  6571  6450  6327  6206  6112
  5961  5839  5718  5684  5599  5531  5551  5613  5705  5793  5868  5946
  6041  6125  6219  6314  6416  6385  6278  6178  6062  5974  5855  5744
  5632  5518  5440  5544  5649  5780  5926  6080  6234  6398  6545  6699
  6854  7008  7162  7316  7470  7624  7790  7935  8101  8243  8394  8549
  8700  8854  9008  9159  9313  9468  9619  9770  9916 10056 10254 10375
 10495 10616 10734 10854 10974 11095 11232 11353 11471 11588 11698 11826
 11932 12051 12170 12290 12401 12517 12635 12751 12868 12986 12938 12831
 12714 12591 12486 12367 12241 12125 12009 11896 11778 11662 11549 11437
 11320 11198 11042 10924 10805 10685 10568 10448 10329 10209  9967  9827
  9681  9530  9378  9227  9076  8924  8773  8622  8469  8316  8176  8014
  7871  7706  7558  7387  7249  7095  6954  6789  6635  6481  6343  6178
  6028  5868  5731  5564  5457  5343  5444  5600  5718  5814  5920  6028
  6138  6247  6358  6310  6206  6099  5991  5881  5767  5668  5460  5351
  5269  5374  5478  5705  5855  6011  6165  6327  6476  6633  6787  6941
  7098  7262  7406  7577  7719  7871  8028  8189  8342  8502  8648  8783
  8950  9104  9258  9409  9564  9715  9855 10149 10272 10392 10512 10633
 10753 10873 10994 11178 11294 11413 11530 11649 11765 11881 11998 12115
 12232 12350 12467 12584 12701 12817 12661 12557 12428 12312 12198 12082
 11965 11849 11733 11616 11500 11385 11266 11147 10948 10830 10710 10589
 10471 10351 10231 10110  9771  9631  9480  9329  9188  9034  8876  8723
  8553  8425  8273  8116  7962  7803  7660  7505  7348  7201  7046  6889
  6729  6572  6418  6263  6112  5961  5812  5488  5385  5277  5173  5290
  5398  5627  5744  5842  5948  6056  6163  6270  6232  6125  6015  5908
  5799  5692  5407  5297  5186  5096  5199  5307  5420  5780  5933  6099
  6247  6401  6558  6715  6872  7032  7188  7331  7485  7642  7790  7962
  8116  8259  8425  8579  8736  8889  9034  9188  9343  9494  9637 10028
 10150 10273 10394 10525 10634 10755 10886 11094 11216 11335 11452 11568
 11685 11804 11921 12037 12154 12273 12389 12506 12372 12256 12139 12022
 11905 11798 11679 11553 11435 11319 11202 11080 10842 10722 10603 10481
 10363 10243 10121 10000  9565  9419  9276  9113  8968  8809  8661  8502
  8355  8202  8054  7900  7735  7590  7435  7273  7119  6965  6808  6654
  6500  6345  6191  6041  5894  5731  5316  5212  5107  5000  5111  5220
  5330  5655  5764  5881  5978  6086  6193  6219  6371  6528  6685  6842
  6996  7153  7310  7466  7623  7777  7934  8088  8245  8399  8566  8710
  8876  9021  9175  9330  9481  9380  9223  9067  8910  8753  8596  8439
  8286  8129  7975  7816  7660  7492  7335  7175  7019  6859  6702  6542
  6385  6558  6716  6876  7046  7201  7361  7518  7673  7840  7999  8163
  8329  8476  8635  8795  8955  9126  9271  9165  9014  8863  8723  8566
  8412  8260  8103  7949  7803  7647  7505  7348  7175  7033  6889  6729
  6902  7059  7214  7364  7518  7686  7829  7983  8146  8299  8443  8609
  8751  8905  9059  8925  8796  8648  8489  8329  8176  8027  7858  7701
  7544  7384  7230  7072  7244  7404  7577  7732  7886  8054  8215  8365
  8525  8685  8809  8670  8579  8456  8312  8150  8004  7858  7719  7564
  7419  7590  7748  7887  8041  8189  8342  8489  8592  8456  8372  8220
  8069  7921  7769  7949  8129  8273  8299  8202  8086]

Обратная трассировка выглядит следующим образом:

Traceback (most recent call last):
File "C:\Users\morga\PycharmProjects\Excel_Upload\venv\Pro-ttiming Development\Triang_Example.py", line 52, in <module>
    ax2.tricontourf(triang2, z,  cmap="Oranges")
  File "C:\Users\morga\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\tri\tricontour.py", line 275, in tricontourf
    return TriContourSet(ax, *args, **kwargs)
  File "C:\Users\morga\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\tri\tricontour.py", line 35, in __init__
    ContourSet.__init__(self, ax, *args, **kwargs)
  File "C:\Users\morga\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\contour.py", line 855, in __init__
    kwargs = self._process_args(*args, **kwargs)
  File "C:\Users\morga\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\tri\tricontour.py", line 47, in _process_args
    tri, z = self._contour_args(args, kwargs)
  File "C:\Users\morga\AppData\Local\Programs\Python\Python37\lib\site-packages\matplotlib\tri\tricontour.py", line 94, in _contour_args
    raise ValueError('z array must not contain non-finite values '
ValueError: z array must not contain non-finite values within the triangulation
...