英文:
Wedge to make half of a circle with variable height and width
问题
以下是您要翻译的代码部分:
我试图在绘图中(matplotlib)将半圆放在图中,但最终得到一条线,因为我的y轴最大值是10,000,x轴最大值是5。
我想知道是否可以将wedge函数的宽度设置为2.5,高度设置为5,000?
def circleplot():
# 准备图形
fig, ax = plt.subplots()
ax.set_xlim(xmin=0, xmax=5)
ax.set_ylim(ymin=0, ymax=10000)
w1 = Wedge((2.5, 5000), 2.5, 0, 180, width=0.1, color='black')
ax.add_patch(w1)
plt.show()
circleplot()
英文:
I'm trying to put half of a circle in a plot (matplotlib) but instead I end up with a line because my y axis max is 10,000 and my x axis max is 5.
I was wondering if it was possible to set the width to 2.5 and the height to 5,000 for the wedge function?
def circleplot():
# preparer le graph
fig, ax = plt.subplots()
ax.set_xlim(xmin=0, xmax=5)
ax.set_ylim(ymin=0, ymax=10000)
w1 = Wedge((2.5, 5000), 2.5, 0, 180, width=0.1, color='black')
ax.add_patch(w1)
plt.show()
circleplot()
答案1
得分: 0
以下是翻译好的代码部分:
import matplotlib.pyplot as plt
import math
def circleplot():
fig, ax = plt.subplots()
ax.set_xlim(xmin=0, xmax=5)
ax.set_ylim(ymin=0, ymax=10000)
ctr = (2.5, 5000)
scl = (2.5, 5000)
xx = []
yy = []
for angle in range(180):
x = ctr[0] + scl[0] * math.cos(angle * math.pi / 180)
y = ctr[1] + scl[1] * math.sin(angle * math.pi / 180)
xx.append(x)
yy.append(y)
xx.append(xx[0])
yy.append(yy[0])
ax.plot(xx, yy)
circleplot()
plt.show()
希望这对您有所帮助。
英文:
Here's what I mean. Just create the points as a circle using normal trigonometry. As long as you apply two different scale for x and y, you can make it look normal. I use 180 points along the half-circle, and it looks pretty smooth. You could probably get by with even fewer than that.
import matplotlib.pyplot as plt
import math
def circleplot():
# preparer le graph
fig, ax = plt.subplots()
ax.set_xlim(xmin=0, xmax=5)
ax.set_ylim(ymin=0, ymax=10000)
ctr = (2.5, 5000)
scl = (2.5, 5000)
xx = []
yy = []
for angle in range(180):
x = ctr[0] + scl[0] * math.cos(angle * math.pi / 180)
y = ctr[1] + scl[1] * math.sin(angle * math.pi / 180)
xx.append(x)
yy.append(y)
xx.append(xx[0])
yy.append(yy[0])
ax.plot(xx,yy)
circleplot()
plt.show()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论