# Text in figure using PyPlot

**URL:** <https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337>\
**Category:** Visualization\
**Created:** [January 6, 2017, 11:22pm UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337 "2017-01-06T23:22:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [January 6, 2017, 11:22pm UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/1 "2017-01-06T23:22:28Z")

</div>

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.

Thanks!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 6, 2017, 11:40pm UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/2 "2017-01-06T23:40:45Z")

</div>

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

```julia
using PyPlot
plot(rand(10))
text(4, 0.5, "hello")

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 6, 2017, 11:45pm UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/3 "2017-01-06T23:45:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [January 6, 2017, 11:55pm UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/4 "2017-01-06T23:55:45Z")

</div>

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.

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

```

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

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [January 6, 2017, 11:57pm UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/5 "2017-01-06T23:57:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 7, 2017, 12:18am UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/6 "2017-01-07T00:18:08Z")

</div>

> [@chobbes](#):
>
> Just to confirm - there isn’t a way of specifying the location of the text like the use of annotate, right?

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:

```julia
plot(rand(10))
text(4, 0.5, "hello", rotation=30)

```

---

<div class="post-metadata">

**Author:** ![chobbes](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@chobbes](https://discourse.julialang.org/u/chobbes)\
**Post date:** [January 7, 2017, 12:21am UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/7 "2017-01-07T00:21:26Z")

</div>

Thanks a lot! I will search more next time.

---

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [January 17, 2018, 5:33am UTC](https://discourse.julialang.org/t/text-in-figure-using-pyplot/1337/8 "2018-01-17T05:33:27Z")

</div>

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?
