1

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:- example figure

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?

1 Answer 1

1

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.