多边形图表

huangapple go评论88阅读模式
英文:

Polygon diagram

问题

这是要翻译的部分:

"I was earlier trying to solve a question that needs to generate this image shown below using matplotlib.

多边形图表

For that, I wrote the code, which was somewhat okay but got stuck. But I got a problem when printing segments of the circle.

Here's my code.

Problem is around, these lines

#Drawing those segments
plt.plot([14.0, 50.0],[ 50.0,86.0 ], color="black")
plt.plot([24.544155877284282, 24.54415587728429],[14.0, 50.0], color="black")
plt.plot([75.4558441227157, 24.544155877284282],[24.544155877284282, 24.54415587728429], color="black")
plt.plot([83.25966317040633, 63.77660356514324],[75.4558441227157, 24.544155877284282] , color="black")
plt.plot([50.0,86.0], [83.25966317040633, 63.77660356514324], color="black")

I got this as an output

多边形图表.

英文:

I was earlier trying to solve a question that needs to generate this image shown below using matplotlib.

多边形图表

For that, I wrote the code, which was somewhat okay but got stuck. But I got a problem when printing segments of the circle.

Here's my code.

Problem is around, these lines

#Drawing those segments
plt.plot([14.0, 50.0],[ 50.0,86.0 ], color="black")
plt.plot([24.544155877284282, 24.54415587728429],[14.0, 50.0], color="black")
plt.plot([75.4558441227157, 24.544155877284282],[24.544155877284282, 24.54415587728429], color="black")
plt.plot([83.25966317040633, 63.77660356514324],[75.4558441227157, 24.544155877284282] , color="black")
plt.plot([50.0,86.0], [83.25966317040633, 63.77660356514324], color="black")

I got this as an output

多边形图表.

答案1

得分: 2

看起来你把值分成了错误的配对 - 像这样

[x1, y1], [x2, y2]

但应该是

[x1, x2], [y1, y2]

plt.plot([14.0, 50.0],[ 50.0,86.0 ], color="black")

#plt.plot([24.544155877284282, 24.54415587728429],[14.0, 50.0], color="red")
plt.plot([24.544155877284282, 14.0],[24.54415587728429, 50.0], color="red")

plt.plot([75.4558441227157, 24.544155877284282],[24.544155877284282, 24.54415587728429], color="blue")

#plt.plot([83.25966317040633, 63.77660356514324],[75.4558441227157, 24.544155877284282] , color="green")
plt.plot([83.25966317040633, 75.4558441227157],[63.77660356514324, 24.544155877284282] , color="green")

#plt.plot([50.0, 86.0], [ 83.25966317040633, 63.77660356514324], color="yellow")
plt.plot([50.0, 83.25966317040633], [86.0, 63.77660356514324], color="yellow")

多边形图表

英文:

It looks like you group values in wrong pairs - like

[x1, y1], [x2, y2]

but it should be

[x1, x2], [y1, y2]

plt.plot([14.0, 50.0],[ 50.0,86.0 ], color="black")

#plt.plot([24.544155877284282, 24.54415587728429],[14.0, 50.0], color="red")
plt.plot([24.544155877284282, 14.0],[24.54415587728429, 50.0], color="red")

plt.plot([75.4558441227157, 24.544155877284282],[24.544155877284282, 24.54415587728429], color="blue")

#plt.plot([83.25966317040633, 63.77660356514324],[75.4558441227157, 24.544155877284282] , color="green")
plt.plot([83.25966317040633, 75.4558441227157],[63.77660356514324, 24.544155877284282] , color="green")

#plt.plot([50.0, 86.0], [ 83.25966317040633, 63.77660356514324], color="yellow")
plt.plot([50.0, 83.25966317040633], [86.0, 63.77660356514324], color="yellow")

多边形图表

答案2

得分: 1

请参考Matplotlib的绘图文档链接plot 函数的参数 xy 是分别带有 x 和 y 坐标的一维数组,形式如 [x1, x2][y1, y2]。因此,您需要将输入的坐标从 [x1, y1], [x2, y2] 转换为 [x1, x2], [y1, y2],如下所示:

plt.plot([14.0, 50.0], [50.0, 86.0], color="black")
plt.plot([24.544155877284282, 14.0], [24.54415587728429, 50.0], color="black")
plt.plot([75.4558441227157, 24.544155877284282], [24.544155877284282, 4.54415587728429], color="black")
plt.plot([83.25966317040633, 75.4558441227157], [63.77660356514324, 24.544155877284282], color="black")
plt.plot([50.0, 83.25966317040633], [86.0, 63.77660356514324], color="black")

或者直接在循环中连接这些点,如下所示:

plt.plot([14.0, 50., 83.25966317040633, 75.4558441227157, 24.544155877284282, 14.0],
         [50.0, 86.0, 63.77660356514324, 24.544155877284282, 24.544155877284282, 50.0],
         color="black")
英文:

See Matplotlib plot doc, the plot function arguments, x and y, are 1-D array with x and y coordinates respectively, like [x1, x2] and [y1, y2]. So you need to swap your input coordinates from [x1, y1], [x2, y2] to [x1, x2], [y1, y2], like:

plt.plot([14.0, 50.0],[ 50.0,86.0 ], color="black")
plt.plot([24.544155877284282, 14.0],[24.54415587728429, 50.0], color="black")                          
plt.plot([75.4558441227157, 24.544155877284282],[24.544155877284282, 4.54415587728429], color="black")
plt.plot([83.25966317040633, 75.4558441227157],[63.77660356514324, 24.544155877284282] , color="black")
plt.plot([50.0,83.25966317040633], [86.0, 63.77660356514324], color="black")

or just connect these points in a loop like:

plt.plot([14.0, 50., 83.25966317040633, 75.4558441227157, 24.544155877284282, 14.0], 
         [50.0, 86.0 , 63.77660356514324, 24.544155877284282, 24.544155877284282, 50.0], 
         color="black")

huangapple
  • 本文由 发表于 2020年1月3日 13:43:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59573711.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定