Text in figure using PyPlot

I’m trying to add some text in a figure made by PyPlot. It seems that the matplotlib command text doesn’t work in PyPlot. So annotate is the only option?

Another question is how to have the in-figure texts tilted/rotated? I’ve been searching but couldn’t find an answer.


The Matplotlib text command works fine for me in PyPlot, e.g.

using PyPlot
text(4, 0.5, "hello")

For future reference, saying something “doesn’t work” isn’t useful. Please paste a complete but minimal (i.e. as short as possible) example of the code you tried and the error message it produced, otherwise it’s impossible to see what the problem is.

Thanks. I confused myself by using the syntax of annotate. Sorry. Just to confirm - there isn’t a way of specifying the location of the text like the use of annotate, right? E.g.

..., xytext=[300,100], textcoords="axes points", ...

Also, is there a way to tilt the text? Thanks!!

Sorry for being too casual. Will paste my MWE from now on. Thanks!!

The first two arguments of text are the coordinates. Typing ?text at the REPL (after using PyPlot) will give you the Matplotlib help (and you can also google it) which explains this.

If you google “rotated text matplotlib” you’ll find lots of examples. There is a rotation keyword that you can pass to text to specify a rotation angle in degrees:

text(4, 0.5, "hello", rotation=30)

Thanks a lot! I will search more next time.

So if I wanted to add data labels to each point in a plot or scatter from PyPlot, would I have to call annotate 100 times if I had 100 points?