制作一个高度和宽度可变的半圆楔形。

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

Wedge to make half of a circle with variable height and width

问题

以下是您要翻译的代码部分:

我试图在绘图中matplotlib将半圆放在图中但最终得到一条线因为我的y轴最大值是10,000x轴最大值是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()

Output:
制作一个高度和宽度可变的半圆楔形。

huangapple
  • 本文由 发表于 2023年5月15日 01:08:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76248738.html
匿名

发表评论

匿名网友

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

确定