matplotlib - 如何在多个图中隐藏轴
问题描述
请问这个隐藏右轴和上轴的代码有什么问题?
import matplotlib.pyplot as plt
fig, ax = plt.subplots(sharex=True, sharey=True, figsize=(10,3))
fig1 = plt.subplot(121)
fig2 = plt.subplot(122)
# Set width of axes
for figures in [fig1, fig2]:
# Removing axis
for side in ['right','top']:
ax.spines[side].set_visible(False)
plt.show()
这适用于非多重情节:
for side in ['right','top']:
ax.spines[side].set_visible(False)
编辑代码:
import matplotlib.pyplot as plt
import seaborn as sns
fig, (ax1, ax2) = plt.subplots(nrows=2, sharex=True, sharey=True, figsize=(10,3))
fig1 = plt.subplot(121)
ax1.set_xlabel(r'$k$')
ax1.set_ylabel(r'$\omega$', rotation='horizontal')
fig2 = plt.subplot(122)
sns.despine()
plt.show()
解决方案
推荐阅读
- selenium - 为什么 base64 屏幕截图在可发送电子邮件的范围报告中显示为空白?
- python - Django 的问题:没有名为“myapp”的模块
- vue.js - 刷新 v-for 循环
- amazon-web-services - EKS 中的 Nginx 入口控制器无法将流量路由到 pod
- php - Laravel hasOneThrough(); 中间表自定义列值
- python - 无法在 Django 中使用自定义表单更新自定义模型
- java - 如果陈述不应该评估为真?
- c++ - 使用指针打印 argv 和 environ
- c++ - OpenGl,glUseProgram() 返回 GL_INVALID_VALUE 即使着色器的 ID 是正确的
- python-3.x - 如何循环输入(看我的代码,你就会明白)