【问题标题】:Why do these two graphs have the same shape?为什么这两个图形具有相同的形状?
【发布时间】:2023-01-10 20:08:13
【问题描述】:

我想转换图形。

但是,显然列表自“list3 = rdp(list2, epsilon=0.5)”以来发生了变化,但图形的形状是相同的。

为什么是这样?

我试过这样。

from rdp import rdp
import numpy as np
import matplotlib.pyplot as plt

list1 = [278.966,713.891,290.003,714.811,298.281,715.731,319.435,717.571,332.312,721.251,344.268,723.091,356.225,725.851,384.737,731.371,395.774,734.131,409.57,734.131,421.527,734.131,435.323,734.131,444.521,730.451,450.039,725.851,462.915,722.171,470.273,721.251,477.631,721.251,510.742,724.011,521.779,724.011,536.495,725.851,543.853,727.691,553.051,733.211,556.729,735.051,560.408,738.73,570.526,742.41,581.563,746.09,597.198,749.77,623.871,750.69,651.463,732.291,655.142,729.531,663.42,726.771,681.815,727.691,700.21,731.371,707.568,733.211,717.685,734.131,730.561,735.051,739.759,735.051,746.197,734.131,754.475,728.611,762.752,719.411,771.95,701.932,773.789,690.892,776.549,672.493,776.549,663.293,779.308,648.574,781.147,637.534,781.147,632.935,778.388,577.737,775.629,555.658,774.709,550.138,772.87,541.858,772.87,533.579,772.87,521.619,771.95,503.22,770.11,488.5,769.191,482.061,769.191,473.781,769.191,457.222,772.87,437.902,775.629,422.263,779.308,406.624,783.907,391.904,788.505,376.265,791.265,367.985,797.703,329.347,758.154,313.707,740.679,310.028,727.802,303.588,718.605,298.988,704.808,294.388,690.093,289.788,666.179,291.628,653.303,298.988,639.507,305.428,630.309,305.428,622.951,303.588,607.315,298.988,601.797,290.708,607.315,270.469,608.235,260.35,609.155,247.47,610.075,232.751,610.075,222.631,610.075,209.752,607.315,200.552,604.556,195.952,591.68,188.592,577.884,186.753,563.168,184.913,550.291,183.073,542.933,182.153,525.458,180.313,509.822,180.313,501.545,181.233,484.07,182.153,466.594,183.073,459.236,185.833,452.798,186.753,445.44,190.432,441.761,193.192,439.002,196.872,435.323,213.431,434.403,219.871,434.403,229.071,438.082,253.91,439.002,261.27,445.44,276.909,448.2,285.189,448.2,287.948,439.922,301.748,402.212,303.588,394.854,307.268,382.898,315.547,372.78,318.307,368.182,316.467,358.065,312.787,347.028,301.748,328.633,300.828,314.837,300.828,304.719,300.828,289.084,299.908,281.726,298.988,276.207,299.908,268.849,301.748,257.812,316.467,254.133,330.267,254.133,338.546,254.133,350.506,254.133,355.106,247.695,371.665,243.096,385.465,243.096,402.024,243.096,407.544,244.936,421.343,247.695,429.623,249.535,442.502,251.374,454.462,251.374,467.341,251.374,474.701,250.454,482.061,247.695,492.18,242.177,509.66,241.257,524.379,243.096,537.259,248.615,551.058,253.214,558.418,256.893,563.937,260.572,573.137,264.251,584.177,266.09,592.456,266.09,603.496,267.93,617.295,268.849,624.655,267.93,634.775,264.251,648.574,261.491,656.854,257.812,666.053,251.374,673.413,247.695,681.693,246.775,692.732,252.294,705.612,255.16,706.532,263.331,713.891,268.849,713.891,278.966,713.891]
X = list1[::2] # Elements from list1 starting from 1 iterating by 2
Y = list1[1::2] # Elements from list1 starting from 0 iterating by 2
# print(X)
# print(Y)
list2 = []
for i in range(len(X)):
    list2.append([X[i],Y[i]])

print(list2)

plt.plot(X, Y)

list3 = rdp(list2, epsilon=0.5)

A = []
B = []
for i in range(len(list3)):
    A.append(list3[i][0])
    B.append(list3[i][1])
    

plt.subplot(1, 2, 1)
orig_graph = plt.plot(A, B)
plt.subplot(1, 2, 2)
rdp_graph = plt.plot(X, Y)
plt.show()```

【问题讨论】:

    标签: python rdp


    【解决方案1】:

    在图表上,肉眼看不到比例引起的变化。设置epsilon=5,它会更引人注目。因此,您可以看到减少列表长度的算法的工作。

    plt.plot(X, Y)
    list3 = rdp(list2, epsilon=0.5)
    print(len(list2), len(list3))
    ----------------------
    165 112
    
    
    plt.plot(X, Y)
    list3 = rdp(list2, epsilon=5)
    print(len(list2), len(list3))
    ----------------------
    165 40
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 2017-03-12
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      相关资源
      最近更新 更多