python - 无法正常显示xlabel / ylabel

python 无法正常显示xlabel / ylabel

在这里插入图片描述

如上述所示,

  • 第一个子图是不带投影的,可以正常显示横纵轴标签和标题
  • 第二个子图带有投影,横纵轴通过手动设置范围,可以正常显示横纵轴标签和标题
  • 第三个子图带有投影,横纵轴的tick label通过gridlines设置,但是添加label之后却无法正常显示

不知道具体是什么原因很奇怪,代码如下:

# -*- coding: utf-8 -*-
"""
Created on Sun Jan 14 21:44:50 2024

@author: Jianpu

@blog:  https://blog.csdn.net/weixin_44237337?spm=1000.2115.3001.5343

@email: Xpji@hhu.edu.cn

@introduction: keep learning although slowly
"""



import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as crs
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter

plt.rcParams['font.family'] = 'Times New Roman'

fig = plt.figure(dpi=200, figsize=(12,8))

ax1 = fig.add_subplot(2, 2, 1,)
ax1.set_xlabel('Xlabel')
ax1.set_ylabel('Ylabel')
ax1.set_title('Title')

# Add the second subplot with PlateCarree projection
ax2 = fig.add_subplot(2, 2, 2, projection=crs.PlateCarree(central_longitude=180))

ax2.set_xticks(np.arange(0, 361, 60), crs=crs.PlateCarree())
ax2.set_yticks(np.arange(-90, 91, 30), crs=crs.PlateCarree())
ax2.xaxis.set_major_formatter(LongitudeFormatter(zero_direction_label=False))
ax2.yaxis.set_major_formatter(LatitudeFormatter())
ax2.set_xlabel('Longitude')
ax2.set_ylabel('Latitude')
ax2.coastlines()
ax2.set_title('Title')


ax3 = fig.add_subplot(2, 2, 3, projection=crs.PlateCarree(central_longitude=0))
ax2.set_xlabel('Longitude')
ax3.set_ylabel('Latitude')
ax3.coastlines()
ax3.gridlines(draw_labels=True, xlocs=[-180, -90, 0, 90,180],linestyle='--')

plt.show()



  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

简朴-ocean

继续进步

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值