发布于2023-05-20 12:42 阅读(1038) 评论(0) 点赞(30) 收藏(2)
I am attempting to plot two half polar charts beside each other using matplotlib, pandas and numpy. The plots are calles c30 and c31. c31 plots well on its own but c30 does not, it appears as a line as you can see in the picture. Also they sit on top of each other instead of side by side. Can anyone advise on how to solve this problem?
What I currently achieve:
import numpy as np
from scipy import interpolate
import pandas as pd
import matplotlib.pyplot as plt
c31df = pd.DataFrame({'measure':[0,7.52,7.91,8.57,8.9,8.94,9.36,9.21,7.97,6], 'angle':[0,52,60,75,90,110,120,135,150,180]})
c30df = pd.DataFrame({'measure':[0,5.1,7.26,7.58,8.1,8.46,8.51,8.9,8.94,7.87], 'angle':[0,52,60,75,90,110,120,135,150,180]})
c31x=c31df.measure[:-1] * np.cos(c31df.angle[:-1]/180*np.pi)
c31y=c31df.measure[:-1] * np.sin(c31df.angle[:-1]/180*np.pi)
c30x=c30df.measure[:-1] * np.sin(c30df.angle[:-1]/180*np.pi)
c30y=c30df.measure[:-1] * np.sin(c30df.angle[:-1]/180*np.pi)
c31x = np.r_[c31x, c31x[0]]
c31y = np.r_[c31y, c31y[0]]
c30x = np.r_[c30x, c30x[0]]
c30y = np.r_[c30y, c30y[0]]
# noinspection PyTupleAssignmentBalance
c31tck, c31u = interpolate.splprep([c31x, c31y], s=0, per=True)
c31xi, c31yi = interpolate.splev(np.linspace(0,1,1000), c31tck)
# noinspection PyTupleAssignmentBalance
c30tck, c30u = interpolate.splprep([c30x, c30y], s=0, per=True)
c30xi, c30yi = interpolate.splev(np.linspace(0,1,1000), c30tck)
def cart2pol(x,y):
rho = np.sqrt(x**2+y**2)
phi = np.arctan2(y,x)
return(rho, phi)
fig = plt.figure(figsize=(12,8))
c31ax = fig.add_subplot(projection='polar')
c31ax.set_theta_zero_location('N')
c31ax.set_theta_direction(1)
c31ax.set_thetamax(180)
c31ax.plot(cart2pol(c31xi, c31yi)[1], cart2pol(c31xi, c31yi)[0], linewidth=1, linestyle='solid', color='red', label='Chart')
c30ax = fig.add_subplot(projection='polar')
c30ax.set_theta_zero_location('N')
c30ax.set_theta_direction(-1)
c30ax.set_thetamax(180)
c30ax.plot(cart2pol(c30xi, c30yi)[1], cart2pol(c30xi, c30yi)[0], linewidth=1, linestyle='solid', color='green', label='Chart')
plt.tight_layout()
plt.show()
I have tried moving theta position around, and it changed the graph but still sat in the wrong position.
更改此行:
c30x=c30df.measure[:-1] * np.sin(c30df.angle[:-1]/180*np.pi)
对此:
c30x=c30df.measure[:-1] * np.cos(c30df.angle[:-1]/180*np.pi)
当您使用 时add_subplot()
,您需要提供预期的布局以及您的子图将适合该布局的位置。其中一种方法是将其称为add_subplot(nrows, nlins, pos)
.
在您的情况下,您需要一行和两列,因此:
c31ax = fig.add_subplot(1, 2, 1, projection='polar')
c30ax = fig.add_subplot(1, 2, 2, projection='polar')
作者:黑洞官方问答小能手
链接:https://www.pythonheidong.com/blog/article/1978745/23e1a2a51586a6e28863/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!