英文:
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
函数的参数 x
和 y
是分别带有 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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论