底图上的Matplotlib圆圈不会转移到球体的另一半

问题描述 投票:0回答:1

我的Matplotlib底图代码出现了另一个问题,地图边缘的圆圈(坐标:180,0)表现得像是结束,但这只是投影的结束。任何人都知道如何解决这个问题? Here the image of issue

import numpy as np
import matplotlib.pyplot as plt

def plot_mwd(RA,Dec,org=0,title='Mollweide projection', 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 = 15, 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)
   phi = np.linspace(0, 2.*np.pi, 72)  #72 points
   r = np.radians(30)
   x = np.radians(180) + r*np.cos(phi)
   y = np.radians(0) + r*np.sin(phi)
   ax.plot(x, y, color="r", linewidth = '0.7')
   fig = plt.gcf()
   ax = fig.gca()


coord = np.array([(180, 0)])
plot_mwd(coord[:,0],coord[:,1], org=0, title ='Galactic Coordinate System', projection = 'aitoff')

plt.show()
python matplotlib matplotlib-basemap
1个回答
0
投票

问题是包装不能像你期望的那样工作,你需要手工制作。换句话说,您需要确保x和y分别明确地介于-pi和pi之间,-pi / 2和pi / 2之间。此外,您无法绘制线条,因为它们将直接连接而不是“围绕投影”方式。

为了清楚起见,我以简单的方式修改了你的功能。你可以做得更好,但在这里你会更清楚地理解。

def plot_mwd(RA,Dec,org=0,title='Mollweide projection', 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 = 15, 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)
    phi = np.linspace(0, 2.*np.pi, 72)  #72 points
    r = np.radians(30)
    x = np.radians(180) + r*np.cos(phi)
    y = np.radians(70) + r*np.sin(phi)
    # Correct wrapping
    x[x>np.radians(180)] = x[x>np.radians(180)] - np.radians(360)
    x[x<np.radians(180)] = x[x<np.radians(180)] + np.radians(360)
    y[y>np.radians(90)] = y[y>np.radians(90)] - np.radians(180)
    y[y<np.radians(90)] = y[y<np.radians(90)] + np.radians(180)
    # Plot only points. No lines
    ax.plot(x, y, color="r", linewidth = '0.0', marker='.')
    fig = plt.gcf()
    ax = fig.gca()
© www.soinside.com 2019 - 2024. All rights reserved.