【问题标题】:How can I split the `ylabel` of a matplotlib figure into rows?如何将 matplotlib 图形的“ylabel”拆分为行?
【发布时间】:2017-09-09 14:50:47
【问题描述】:

如何将 matplotlib 图形的 ylabel 拆分为行?我想保持 y 轴上的 ylabel 旋转。以here's my subplot 为例,相关代码如下:

plt.ylabel('Spacing of Zeroes of $J_{\\nu}(x)$', rotation=0)

当我尝试这样做时:

plt.ylabel('Spacing of Zeroes of $J_{\\nu}(x)$', rotation=0, ncol=2)

我收到此错误:

AttributeError: Unknown property ncol

【问题讨论】:

  • 我不确定 columnate 是不是一个词,但如果是,我不明白。另外,为什么要在 x 轴上放置 ylabel?
  • 通过分栏,我的意思是将标签分成两列,我的目标是适应 ylabel 而不会在左侧留下大量空白。 x 轴上的 ylabel 是一个错字,我的意思是 y 轴。
  • 我还是不明白。如果你有一列长度为 N 的字符串,你把它分成两列,每列长度为 N/2 的字符串,结果将是两列,但字符串的宽度仍然是 N/2+N/ 2 = N。
  • 你是对的。我需要行,而不是列。不敢相信我错过了,感谢您指出。

标签: python-3.x matplotlib multiple-columns axis-labels


【解决方案1】:

你可以使用它。 https://matplotlib.org/2.0.2/examples/pylab_examples/multiline.html

plt.xlabel('this is a xlabel\n(with newlines!)')
plt.ylabel('this is vertical\ntest', multialignment='center')

【讨论】:

    【解决方案2】:

    我的建议是在字符串中引入换行符。

    plt.ylabel('Spacing of\nZeroes of\n$J_{\\nu}(x)$', rotation=0, ha="right")
    

    【讨论】:

    • 简单而完美!另外,我可以选择它分裂的地方。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2020-04-21
    • 2013-04-15
    • 2022-11-13
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    相关资源
    最近更新 更多