【问题标题】:matplotlib unexpected results polar plotmatplotlib 意外结果极坐标图
【发布时间】:2017-03-31 05:00:52
【问题描述】:

我正在尝试使用 matplotlib 绘制简单的函数 r = 3*sin(2*theta):

import numpy as np
import matplotlib.pyplot as plt
theta = np.arange(0,2*np.pi,0.01)
r = 3.0*np.sin(2.0*theta)
ax = plt.subplot(111, projection='polar')
ax.plot(theta, r)
plt.show()

这是我得到的结果(不正确):

这是我期望看到的(wolfram alpha):

我错过了什么吗? 谢谢!

【问题讨论】:

  • matplotlib polar 显然没有负面作用r 请参阅stackoverflow.com/questions/42982290/… 中的评论链接
  • @f5r5e5d 你回答了我的问题
  • @f5r5e5d 你能把这个作为你的答案吗?谢谢!

标签: python numpy matplotlib


【解决方案1】:

这修补了 neg r 的极坐标图

import numpy as np
import matplotlib.pyplot as plt
theta = np.arange(0,2*np.pi,0.01)
r = 3.0*np.sin(2.0*theta)
theta = theta + (1 - np.sign(r))*np.pi/2 # add pi to points with negative r values
r = np.abs(r) # make all r values postive to fake out matplotlib
ax = plt.subplot(111, projection='polar')
ax.plot(theta, r)
plt.show()

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多