Matplotlib版本1.5.3与2.2.2在极轴上显示 [英] Matplotlib version 1.5.3 vs 2.2.2 imshow on polar axis
本文介绍了Matplotlib版本1.5.3与2.2.2在极轴上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用版本2.2.2结果:
解决方案
您可以创建两个轴,一个在背景中的笛卡尔轴显示您的图像,一个在前景中的极轴以...成为所需的极轴.
将 numpy 导入为 np导入matplotlib.pyplot作为pltdata = plt.imread("https://matplotlib.org/devdocs/_images/sphx_glr_firefox_001.png")无花果= plt.figure()#在背景中创建轴以显示笛卡尔图像ax0 = fig.add_subplot(111)ax0.imshow(数据)ax0.axis("关闭")#在前景中创建极轴并删除其背景#看穿ax = fig.add_subplot(111,polar = True,label ="polar")ax.set_facecolor("无")plt.show()
I am trying to plot using imshow
in a polar graph. This worked in matplotlib version 1.5.3 but no longer works in version 2.2.2. Is there an alternate way to use do this? I know I can use pcolormesh
or contourf
to do a similar thing, but I would highly prefer to use imshow. An example is below:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
def main():
print matplotlib.__version__
data = np.random.randint(1, 100, (100, 100))
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.imshow(data, extent=[0, 2*np.pi, 0, 90])
plt.show()
if __name__ == '__main__':
main()
Version 1.5.3 Result: Version 2.2.2 Result:
解决方案
You can create two axes, one cartesian axes in the background to show your image and a polar axes in the foreground to... be a polar axes as desired.
import numpy as np
import matplotlib.pyplot as plt
data = plt.imread("https://matplotlib.org/devdocs/_images/sphx_glr_firefox_001.png")
fig = plt.figure()
#create axes in the background to show cartesian image
ax0 = fig.add_subplot(111)
ax0.imshow(data)
ax0.axis("off")
# create polar axes in the foreground and remove its background
# to see through
ax = fig.add_subplot(111, polar=True, label="polar")
ax.set_facecolor("None")
plt.show()
这篇关于Matplotlib版本1.5.3与2.2.2在极轴上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文