我可以在matplotlib支持的AItoff投影中反向Xaxis吗? (这不是重复的。)
我想在我的Python脚本中扭转我的AiToff投影的Xaxis。这是一个示例
import numpy as np
import matplotlib.pyplot as plt
X=[-1,0,1,2]
Y=[0,1,0,1]
plt.figure()
plt.subplot(111,projection="aitoff")
plt.grid(True)
plt.gca().invert_xaxis()
plt.scatter(X,Y)
plt.show()
plt.gca()。invert_xaxis()将显示错误。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/hea/.local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3525, in invert_xaxis
self.xaxis.set_inverted(not self.xaxis.get_inverted())
File "/home/hea/.local/lib/python3.10/site-packages/matplotlib/axis.py", line 2243, in set_inverted
self.axes.set_xlim(sorted((a, b), reverse=bool(inverted)), auto=None)
File "/home/hea/.local/lib/python3.10/site-packages/matplotlib/projections/geo.py", line 151, in set_xlim
raise TypeError("Changing axes limits of a geographic projection is "
TypeError: Changing axes limits of a geographic projection is not supported. Please consider using Cartopy.
如果我删除plt.gca()。invert_xaxis(),它将正常工作。有什么办法可以修复它?
I want to reverse my xaxis of my aitoff projection in my python script. Here is an example
import numpy as np
import matplotlib.pyplot as plt
X=[-1,0,1,2]
Y=[0,1,0,1]
plt.figure()
plt.subplot(111,projection="aitoff")
plt.grid(True)
plt.gca().invert_xaxis()
plt.scatter(X,Y)
plt.show()
plt.gca().invert_xaxis() will show error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/hea/.local/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3525, in invert_xaxis
self.xaxis.set_inverted(not self.xaxis.get_inverted())
File "/home/hea/.local/lib/python3.10/site-packages/matplotlib/axis.py", line 2243, in set_inverted
self.axes.set_xlim(sorted((a, b), reverse=bool(inverted)), auto=None)
File "/home/hea/.local/lib/python3.10/site-packages/matplotlib/projections/geo.py", line 151, in set_xlim
raise TypeError("Changing axes limits of a geographic projection is "
TypeError: Changing axes limits of a geographic projection is not supported. Please consider using Cartopy.
If I remove plt.gca().invert_xaxis(), it will work fine. Is there any way I can fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个解决方法,但是需要一些特殊的
plt.plt.pause
s才能使其正常工作(如果省略了这些暂停,则在操纵后根本没有显示XTICKS):而不是反转X轴,尝试翻转X坐标和Xticklabels:
I have a workaround for you, but some peculiar
plt.pause
s are required to make it work (if theses pauses are omitted, no xticks are displayed for me at all after the manipulation):Instead of inverting the x-axis, try both flipping the x-coordinate and the xticklabels: