Chef1075
Chef1075

Reputation: 2724

Labeling an axis in matplotlib with formatting strings

I'm trying to put label an axis, and I seem to be getting an error. I want to call the names of the strings I set earlier in the code.

ticker = 'RY', 'CM' 

Then later on I call the names when naming the graph.

plt.ylabel('Price Spread between %s and %s') % (ticker[0], ticker[1])

But, I get this error:

TypeError: unsupported operand type(s) for %: 'Text' and 'tuple'

What am I doing wrong here?

Upvotes: 0

Views: 55

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

Change the formatting line present on your code to,

plt.ylabel('Price Spread between %s and %s' % (ticker[0], ticker[1]))

Upvotes: 2

Related Questions