matplotlib 如何旋转自定义xtick标签[重复]

wdebmtf2  于 2023-06-23  发布在  其他
关注(0)|答案(1)|浏览(95)

此问题已在此处有答案

Rotate axis tick labels(13个回答)
14天前关闭
我有下面的一行,我用来添加标签到我的自定义cbar,但我不知道如何旋转这些标签

MyCustomBar.set_ticklabels(['< 50 \nand \ndecreasing', '< 50 \nand increasing \nor unchanged', '> 50 \nand decreasing  \nor unchanged', '> 50 \nand \nincreasing'])

我尝试使用,rotation = 45,但似乎不存在set_ticklabels

yyyllmsg

yyyllmsg1#

你可以这样试试:

import pandas as pd
from matplotlib import pyplot as plt

# Toy dataframe
df = pd.util.testing.makeDataFrame()[0:4]

plt.plot(df.index, df["A"], "o--", df.index, df["B"], "x-")
plt.xticks(
    df.index,
    [
        "< 50 \nand \ndecreasing",
        "< 50 \nand increasing \nor unchanged",
        "> 50 \nand decreasing  \nor unchanged",
        "> 50 \nand \nincreasing",
    ],
    rotation=45,
)
plt.show()

相关问题