【问题标题】:how to plot polar and cartesian subplot in one plot as shown in picture如图所示,如何在一个图中绘制极坐标和笛卡尔子图
【发布时间】:2019-10-13 20:50:11
【问题描述】:

我想生成一个半笛卡尔半极坐标图。例如高斯曲线的一半是极坐标格式,另一半是笛卡尔格式。哪个是最好的方法?

我尝试过共享 y 轴,但没有成功为一个绘图采用两种不同类型的格式。

import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0,(np.pi)/2)
r = np.sin(theta)

fig = plt.figure()
ax = fig.add_subplot(211, polar=True)
c = ax.scatter(theta, r, c=r, s=5, cmap='hsv', alpha=0.85)

ax.set_thetamin(0)
ax.set_thetamax(90)

ax1=fig.add_subplot(212) #, sharey='ax')
fig, (c, d) = plt.subplots(ncols=2,sharey=True)
d=ax1.scatter(theta,r)
plt.show() 

【问题讨论】:

    标签: matplotlib subplot polar-coordinates cartesian


    【解决方案1】:
    import matplotlib.pyplot as plt
    import numpy as np
    
    theta = np.linspace(0,(np.pi)/2)
    r = np.sin(theta)
    
    fig = plt.figure(figsize=(6.4, 3.25))
    fig.subplots_adjust(wspace=0)
    ax1 = fig.add_subplot(121)
    ax1.grid()
    ax2 = fig.add_subplot(122, polar=True)
    ax2.set_thetamin(0)
    ax2.set_thetamax(90)
    
    ax1.set_ylim(0, 1.05)
    ax2.set_ylim(0, 1.05)
    
    sc1 = ax1.scatter(np.rad2deg(theta), r, c=r, s=5, cmap='hsv', alpha=0.85)
    sc2 = ax2.scatter(theta,r, c=r, s=5, cmap='hsv', alpha=0.85)
    plt.show() 
    

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多