Issue
How can I change the values dislayed in the top right corner of matplot figure? By default it is showing coordinates of the current cursor position but I'd prefer it to show the value of displayed data for current x cursor's coordinate. I marked these values in the attached picure. diagram
EDIT: here's a simple code. Pls tell me how to solve described above problem for this example:
import numpy as np
from matplotlib import pyplot as plt
x = np.sin(np.arange(0,100,0.1))
fig, ax = plt.subplots()
ax = plt.plot(x)
plt.show()
Solution
You can define the format of these coordinates in the NavigationToolbar using format_coord:
import numpy as np
from matplotlib import pyplot as plt
def f(x):
return np.sin(x)
x = np.arange(0, 100, 0.1)
y = f(x)
fig, ax = plt.subplots()
ax.plot(x, y)
#this can be defined for each axis object either using a def function
#or in simple cases a lambda function
ax.format_coord = lambda x, y: f"x: {x:.2f}, f(x): {f(x):.4f}"
plt.show()
Answered By - Mr. T
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.