0
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-1,5)
y = 6 - np.square(x-1)

fig, ax = plt.subplots()
ax.plot(x, y, 'b')
ax.scatter(x, y, color='m', zorder=10)
ax.set_xlabel('x')
ax.set_ylabel('y')

This creates the following:

f(x) = 6 - (x-1)^2

This function is increasing for all values of x < 1 and increasing for all values of x > 1. Is there a simple way that I can put the text "Increasing" like an x label but centered below the x ticks of 0 and 1, "Decreasing" like an x label but centered below 3, and move the "x" xlabel lower such that it has a lower vertical position than "Increasing" and "Decreasing"? I'd rather not do this with ax.text() unless I absolutely have to.

Forklift17
  • 2,245
  • 3
  • 20
  • 32
  • 1
    Maybe the answer to https://stackoverflow.com/questions/47342006/how-do-i-get-more-columns-of-xticklabels/47349600#47349600 will help. Although, using `ax.text` does seem easier than that manipulating `xticklabels` – krm Dec 14 '20 at 17:32

1 Answers1

0

Maybe use text? I have tried changing the labels but this seems cumbersome. Unfortunately you have to set the text coordinates "manually". Note that you can use newline in the ticks to move them down.

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-1,5)
y = 6 - np.square(x-1)

fig, ax = plt.subplots()

ax.text(0.5, -4.6, 'Increasing', ha="center")
ax.text(3, -4.6, 'Decreasing', ha="center")

ax.plot(x, y, 'b')
ax.scatter(x, y, color='m', zorder=10)
ax.set_xlabel('\nx')
ax.set_ylabel('y')

which produces

enter image description here

GrimTrigger
  • 571
  • 1
  • 5
  • 10