【问题标题】:How to make smooth circles on basemap projections in Matplotlib by Python如何通过 Python 在 Matplotlib 中的底图投影上制作平滑的圆圈
【发布时间】:2018-03-29 20:23:18
【问题描述】:

我不是 Python 的高级用户,但由于我的科学工作,我得到了使用 Matplotlib 绘制一些图表的任务。 现在我必须根据底图投影绘制平滑变形,围绕给定点画圈。但结果我得到了带有虚线的圆圈:

import numpy as np
import matplotlib.pyplot as plt

def plot_mwd(RA,Dec,org=0,title='GCS', projection='aitoff'):

    x = np.remainder(RA+360-org,360) # shift RA values
    ind = x>180
    x[ind] -=360    # scale conversion to [-180, 180]
    x=-x    # reverse the scale: East to the left
    tick_labels = np.array([150, 120, 90, 60, 30, 0, 330, 300, 270, 240, 210])
    tick_labels = np.remainder(tick_labels+360+org,360)
    fig = plt.figure(figsize=(10, 5))
    ax = fig.add_subplot(111, projection=projection, axisbg ='LightCyan')
    ax.scatter(np.radians(x),np.radians(Dec), s = 30, c = 'k', marker = '.')  # convert degrees to radians
    ax.set_xticklabels(tick_labels)     # we add the scale on the x axis
    ax.set_title(title)
    ax.title.set_fontsize(15)
    ax.xaxis.label.set_fontsize(12)
    ax.yaxis.label.set_fontsize(12)
    ax.grid(color='tab:gray', linestyle='-', linewidth=0.2)
    circle1 = plt.Circle((np.radians(35),np.radians(30)), np.radians(40), color='g', fill = False) # Circle parameters
    fig = plt.gcf()
    ax = fig.gca()
    ax.add_artist(circle1)

coord = np.array([(325,30)]) # coordinates that will be ploted
plot_mwd(coord[:,0],coord[:,1], org=0, title ='GCS', projection ='aitoff')   

plt.show()

【问题讨论】:

标签: python matplotlib matplotlib-basemap


【解决方案1】:

函数plt.Circle() 不允许指定要绘制的顶点数。因此,您需要编写自己的代码。这是我的代码,你可以试试:

# Plot circle with 36 vertexes
phi = np.linspace(0, 2.*np.pi, 36)  #36 points
r = np.radians(40)
x = np.radians(35) + r*np.cos(phi)
y = np.radians(30) + r*np.sin(phi)
ax.plot(x, y, color="g")

用我的代码代替你的两行代码:

circle1 = plt.Circle((np.radians(35), np.radians(30)), np.radians(40), color='g', fill = False)  # Circle parameters
ax.add_artist(circle1)

生成的图像:

【讨论】:

  • 非常感谢你,你是我的救星。我希望这对我的主管来说已经足够了。
猜你喜欢
  • 1970-01-01
  • 2019-07-26
  • 1970-01-01
  • 1970-01-01
  • 2017-07-30
  • 1970-01-01
  • 2019-11-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多