Reputation: 3910
I have list of data want to plot on a subplot. Then I want to lable ylable with different set of colour. See the simple code example below:-
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('yellow red blue')
plt.show()
This produces the following image:-
In the resultant image ylable is named as 'yellow red blue' and all in black colour. But I would like to have this label coloured like this:-
'yellow' with yellow colour, 'red' with red colour and 'blue' with blue colour.
Is it possible with matplotlib?
Upvotes: 1
Views: 37
Reputation: 18677
No. You can't do this with a single text object. You could manually add three different labels, i.e.:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
ax = plt.gca()
ax.text(-0.1, 0.4, 'yellow', color='yellow', rotation=90, transform=ax.transAxes)
ax.text(-0.1, 0.5, 'red', color='red', rotation=90, transform=ax.transAxes)
ax.text(-0.1, 0.6, 'blue', color='blue', rotation=90, transform=ax.transAxes)
plt.show()
Upvotes: 1