如何旋转自定义 cbar 标签

How to rotate custom cbar labels

我使用以下行向我的自定义 cbar 添加标签,但我不知道如何旋转这些标签

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

我尝试使用 ,rotation = 45,但 set_ticklabels

似乎不存在

你可以这样试试:

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()