0
問題: 繪製封閉的2D多邊形工作正常。 當我嘗試繪製它1D(通過用一個常量替換第二個維度)時,它在某些特殊情況下失敗:然後多邊形(它變成一條線)沒有完全繪製。線部分未繪製
我試了一下:
- 繪製不同的樣式像
. , o --
其中,同時非視距樣的風格下工作只有後者重現問題。 - 移動/滾動多邊形陣列,當移動1或2時不起作用,但3和4移動解決了問題。
- 問了一個無知的朋友^^
- 通過直接繪製
x.min()
和x.max()
之間的一條直線來幫助我自己。 - 爲了簡單起見,我刪除了z-Data。當繪製與z結合的x時,它也起作用 - 只要z遠離恆定。但是,然後我得到一個搖擺的圖表,而不是一條直線。
我試圖減少某些特殊情況下的數據,但沒有得到很好的結果。 下面是生成圖像的工作小例子,對於長數據集感到抱歉,但無法確定在保持問題可重現性的同時刪除哪些值。
import numpy as np
from matplotlib import pyplot as plt
s = np.array([
[-0.08527125, 0.08810856],
[-0.08967261, -0.06748633],
[-0.08772675, -0.08396971],
[-0.08766724, -0.08440267],
[-0.08748191, -0.08521958],
[-0.08438602, -0.09529874],
[-0.08385044, -0.09684308],
[-0.08202714, -0.10180355],
[-0.07874478, -0.1066276 ],
[-0.07857811, -0.10686354],
[-0.07789635, -0.10778213],
[-0.07781094, -0.10789337],
[-0.07710836, -0.10880646],
[-0.07007289, -0.11655674],
[-0.06962708, -0.11703841],
[-0.06727917, -0.11933749],
[-0.06584873, -0.12070607],
[-0.06552574, -0.12100522],
[-0.06527846, -0.12121293],
[-0.06401669, -0.12214381],
[-0.06349801, -0.12245992],
[-0.06328962, -0.12258028],
[-0.0627093 , -0.12290901],
[-0.06225359, -0.12314782],
[-0.06116991, -0.12368258],
[-0.06041895, -0.12403051],
[-0.06017477, -0.12413955],
[-0.05992829, -0.12424804],
[-0.04659197, -0.13006904],
[-0.04634663, -0.13017319],
[-0.04628731, -0.1301966 ],
[-0.04567821, -0.13041967],
[-0.04552972, -0.13047215],
[-0.04521702, -0.13058213],
[-0.00325617, -0.14513102],
[ 0.00180445, -0.14683444],
[ 0.00950078, -0.14923653],
[ 0.01392647, -0.15030046],
[ 0.01518804, -0.15045976],
[ 0.02734024, -0.15177574],
[ 0.02813995, -0.15177997],
[ 0.02882764, -0.15176844],
[ 0.02947446, -0.15171012],
[ 0.03001744, -0.15165147],
[ 0.0309922 , -0.15149313],
[ 0.03121784, -0.15145567],
[ 0.031327 , -0.15143527],
[ 0.03142507, -0.15141573],
[ 0.03150791, -0.15139799],
[ 0.03222764, -0.15124224],
[ 0.03798838, -0.14988557],
[ 0.038991 , -0.1496481 ],
[ 0.0391266 , -0.14961472],
[ 0.03920601, -0.14959498],
[ 0.03938681, -0.14954736],
[ 0.03991586, -0.14940614],
[ 0.05465674, -0.14538513],
[ 0.05500815, -0.14528457],
[ 0.05512499, -0.14524203],
[ 0.05522656, -0.14520209],
[ 0.05558739, -0.14504381],
[ 0.05580602, -0.1449474 ],
[ 0.05609256, -0.14478439],
[ 0.05713959, -0.14412759],
[ 0.05743526, -0.14392656],
[ 0.05889567, -0.14277855],
[ 0.06059875, -0.14143159],
[ 0.06530732, -0.13766523],
[ 0.06933674, -0.13424303],
[ 0.0702827 , -0.13335664],
[ 0.07036637, -0.13327235],
[ 0.07405533, -0.12951652],
[ 0.07810863, -0.125367 ],
[ 0.08087981, -0.12226141],
[ 0.08176499, -0.12123622],
[ 0.08381519, -0.1150717 ],
[ 0.08734418, -0.0927558 ],
[ 0.08230393, 0.09131774],
[ 0.08183173, 0.097691 ],
[ 0.08169106, 0.09931977],
[ 0.08130204, 0.10177584],
[ 0.07914312, 0.11230088],
[ 0.07895476, 0.11316267],
[ 0.07514703, 0.12076318],
[ 0.07464758, 0.12166996],
[ 0.0733333 , 0.12382546],
[ 0.07297538, 0.12425848],
[ 0.06620658, 0.13199037],
[ 0.05294461, 0.14660768],
[ 0.05262742, 0.14694802],
[ 0.05097036, 0.14849098],
[ 0.04972845, 0.14937964],
[ 0.04815287, 0.15002114],
[ 0.04783434, 0.15013311],
[ 0.04757239, 0.15022502],
[ 0.02928349, 0.15634586],
[ 0.02842644, 0.15662035],
[ 0.02776939, 0.15677726],
[ 0.0270936 , 0.15690821],
[ 0.02666639, 0.15698384],
[ 0.02610376, 0.15707915],
[ 0.02601474, 0.15709266],
[ 0.025126 , 0.15722434],
[ 0.02474755, 0.15727606],
[ 0.02296123, 0.15742128],
[ 0.02202472, 0.15744494],
[ 0.02086636, 0.15744469],
[ 0.01967163, 0.15742308],
[ 0.01872141, 0.15737815],
[ 0.01568162, 0.15718458],
[-0.00722516, 0.15361993],
[-0.00785781, 0.15350418],
[-0.02865655, 0.14966376],
[-0.02928172, 0.1495445 ],
[-0.02970399, 0.14942282],
[-0.03124785, 0.14896281],
[-0.03160079, 0.14884731],
[-0.03311488, 0.14832349],
[-0.04643741, 0.14369722],
[-0.04831254, 0.14301643],
[-0.04846789, 0.14294296],
[-0.04902343, 0.14264339],
[-0.04980039, 0.14218488],
[-0.05127431, 0.14122099],
[-0.05343824, 0.13978482],
[-0.06641953, 0.1306598 ],
[-0.06719992, 0.13009146],
[-0.06732267, 0.12997761],
[-0.06842394, 0.12872382],
[-0.06895024, 0.12808815],
[-0.07854825, 0.11574519],
[-0.08365013, 0.10504 ],
[-0.0837306 , 0.10486896],
[-0.08384365, 0.10417084],
[-0.08444646, 0.09768441]])
# make first and last point the same, to close the circle
s = np.concatenate([s,s[:1]])
y = s[:,0]
x = s[:,1]
# plot the polygon xy
plt.plot(x, y, 'b--', label='Polygon with x/y')
# plot only x values of the polygon (does not work)
plt.plot(x, np.zeros(len(x)), 'g-', linewidth=10, label='does not stretch over red dots')
# do the same, but with dots to show x values (does work)
plt.plot(x, np.zeros(len(x)), 'r.')
# do the same, a little bit lower, but with shifted/rolled x values.
# rolled by 1 or 2 does not help, but by 3 or 4 does.
plt.plot(np.roll(x,3), np.ones(len(x))-1.02, '-', color="lightgreen", linewidth=10, label="stretches over red dots")
# do the same again with dots to show x values
plt.plot(np.roll(x,3), np.ones(len(x))-1.02, 'r.')
plt.legend(loc='lower center').get_frame().set_alpha(1)
plt.show()
Python 3.5 x64通過Windows10中的Anaconda。 Matplotlib是v2.0.0
我明白你的觀點,但無法理解它是如何應用於此的。 正在繪製一系列與繪製一系列線條不同的多邊形線條嗎?如果我不關閉線來形成一個多邊形('s = np.concatenate([s,s [:1]])'),而是保留'min()!= max()',它會顯示同樣的行爲。 – nitzel
我同意這很奇怪,但如果對值plt.plot(np.sort(x),np.zeros(len(x))進行排序,它也可以正常工作。 – ImportanceOfBeingErnest
是的,儘管繪製的線條排序是(內部)與未排序的非常不同 - 反正,它們應該在視覺上難以區分 我會讓問題再公開幾天,可能會出現一個pyplotguru,告訴我們在matplotlib中有一個特殊的修剪算法惡毒地解剖我的圖表;) – nitzel