軸/目盛りラベルの色付け 質問する

軸/目盛りラベルの色付け 質問する

Y 軸ラベルと目盛りラベルを赤にするにはどうすればよいでしょうか?

たとえば、「y ラベル」と 0 から 40 までの値は赤色になります。サンプル画像

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)

fig = plt.figure()
ax = plt.subplot(111)
ax.set_ylabel("y-label")

for i in xrange(5):
    ax.plot(x, i * x, label='$y = %ix$' % i)

ax.legend()

plt.show()

ベストアンサー1

  label = plt.ylabel("y-label")
  label.set_color("red")

同様に、目盛りラベルを取得して変更することもできます。

[i.set_color("red") for i in plt.gca().get_xticklabels()]

おすすめ記事