python - 是否可以在 matplotlib hexbin 图中命名 x 轴和 y 轴?

标签 python matplotlib

我可以生成这样的十六进制图(代码取自 http://matplotlib.org/examples/pylab_examples/hexbin_demo.html )

import numpy as np
import matplotlib.cm as cm
import  matplotlib.pyplot as plt

n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()

plt.subplots_adjust(hspace=0.5)
plt.subplot(121)
plt.hexbin(x,y, cmap=cm.jet)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("Hexagon binning")
cb = plt.colorbar()
cb.set_label('counts')

plt.subplot(122)
plt.hexbin(x,y,bins='log', cmap=cm.jet)
plt.axis([xmin, xmax, ymin, ymax])
plt.title("With a log color scale")
cb = plt.colorbar()
cb.set_label('log10(N)')

plt.show()

有没有办法用轴名称来标记 hexbin 的 x 轴和 y 轴?我希望“x-label”之类的内容显示在 x 轴数字下方,“ylabel”显示在 y 轴数字的左侧。这将是对颜色栏上标签的补充。

最佳答案

您可以使用xlabelylabel matplotlib 命令:

plt.xlabel('x-label')
plt.ylabel('y-label')

关于python - 是否可以在 matplotlib hexbin 图中命名 x 轴和 y 轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12397657/

相关文章:

python - 从 matplotlib 中的颜色图中获取单个颜色

python - matplotlib - 带有弧度角标签的极坐标图

python - 如何舍入 Matplotlib 轴脊柱的连接

python - pyplot根据两条曲线的变化率填充它们

python - 将随机排列代码从 MATLAB 移植到 Python

python - Debug Exact Cover Pentominoes,维基百科示例不完整?或者...我误解了一些东西(包括代码)

Python AWS SQS 与 MOTO 模拟

python - 如何在 discord.py 中调用 on_member_update 时访问成员?

python - 用数字列表拆分字符串

python - Matplotlib:savefig 为具有对数标度 Y 轴的条形图生成不正确的 SVG 图像