python画虚线园圆_如何通过Python在Matplotlib中对底图投影制作平滑的圆

I'm not advanced user of Python, but due to my scientific work I got tasks to plot some graphs with Matplotlib.

Now I have to draw smooth-deformed according to the basemap projection, circles around given point. But in the result I got circles with broken lines:

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()

解决方案

The function plt.Circle() does not allow to specify the number of vertexes to plot. So, you need to write up your own code. Here is my code that you may try:

# 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")

Use my code in place of yours 2 lines:

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

ax.add_artist(circle1)

The resulting image:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值