0

I am trying to add a simple text us ax.text() inside a plot, but when I run the code, I can see that the text does not appear.


lvl1 = price_max - 0.236 * delta
lvl2 = price_max - 0.382 * delta

fig, ax = plt.subplots()
candlestick_ohlc(ax, ohlc.values, width = 0.6,
                 colorup='green', colordown='red', alpha=0.8)

ax.axhspan(lvl1, price_min, alpha=0.4, color = 'lightsalmon')
ax.text(lvl1, lvl1, '23.6')

plt.show()

5
  • please provide a minimal reproducible example. Commented Dec 31, 2020 at 14:15
  • Sorry. Just updated Commented Dec 31, 2020 at 14:17
  • no, I mean, why not use either a small df that you build (with hopefully no more than a couple lines of code, e.g. using np.random or similar), or load from some public place (e.g. from sklearn.datasets import load_iris) Commented Dec 31, 2020 at 14:20
  • The data is taken from coinmarketcap api. I can post the full code? Commented Dec 31, 2020 at 14:22
  • 1
    certainly not. Try to get a similar example that boils your problem down to the essence and can easily be reproduced by any SO-er. You'll be amazed how quickly you'll get an answer then. Commented Dec 31, 2020 at 14:23

1 Answer 1

1

As we do not have the data, I can only give you a few advices from my experience in this kind of case :

  • Do 'Price' and 'Date' appear as label ? If not, you might have an error prior to the text writing
  • What is the value of lvl1 and is it a value that appear in both your xaxis and your yaxis ?
  • To debug, I usually hand-type values instead of lvl1 and watch if the text appears, and where it does appear.

I hope theses three small advices will help you.

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

4 Comments

Thank you for your input. Yes, "Price" and "Date" appear as x and y labels. Lvl1 refers to fibonannci retracement values (23.8%)
Thank you for quick response. The problem is solved now. Happy New Year to everybody.
Very good ! So, how did you fix it ? Happy new year !
I just looked into examples with timestamps. I was using the wrong x value lol. So I justed ax.text(dt.date(a date of my choice), lvl1, "my string"). Before, I was using ax.text(lvl1, lvl1 ,"my string") where lvl1 is a fibonacci number I calculated. But the plot as dates on the x-axis, so that is why the string was not showing :D. Sometimes the brain does not function lol.

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.