3

I have a function plotted using pyplot. When I move the cursor over the window, I can see the values for X and Y of the location of the cursor at the bottom-left of the window (display as, for example, x = 4.27567e+06 y = 6.98764e-09).

How can I change the number of significant digits of those values? I've tried playing with the axis settings and tick settings, but it doesn't seem to help.

As you can see in the example I gave above, right now the resolution is 6 significant digits, but I need resolution of 8 or more digits.

FYI, the array I am plotting has points separated by intervals much smaller than what I need to display, so that's not the issue.

Is there a command in matplotlib to do this?

Thanks.

diemilio
  • 53
  • 9
  • Could you please post some code that generates a plot with the digit issue you're referring to. – tom10 Jul 11 '15 at 19:14
  • `import numpy as np` `import matplotlib.pyplot as plt` `f0 = 4.0e6` `BW = f0/100.0e3` `f = np.linspace(f0 - 10*BW, f0 + 10*BW,10001)` `g = 1.0e-12*f**2` `plt.figure(1)` `plt.axis([f0-10*BW, f0 + 10*BW, 0, 20])` `plt.plot(f,g,'b')` `plt.grid()` `plt.show()` – diemilio Jul 12 '15 at 12:43
  • possible duplicate of [In a matplotlib figure window (with imshow), how can I remove, hide, or redefine the displayed position of the mouse?](http://stackoverflow.com/questions/14349289/in-a-matplotlib-figure-window-with-imshow-how-can-i-remove-hide-or-redefine) – drescherjm Jul 21 '15 at 02:38

1 Answers1

6

You can entirely customize the text that displays info about the cursor's current location:

ax = plt.gca()
ax.format_coord = lambda x,y: '%10d, %10d' % (x,y)
user670416
  • 736
  • 4
  • 12
  • Thanks! That did the job, but I had to use %10f rather than %10d. One question though, what type of format is that? When I used %10e (to get it in scientific format) the number of significant digits did not increase. – diemilio Jul 16 '15 at 14:26
  • @diemilio: If this answers your question, it would be helpful if you were to accept the answer by clicking on the check mark to the left. – tom10 Aug 10 '15 at 02:24
  • @user670416 Hi. Checked this in Python 3.7. Doesn't do anything unfortunately. Any ideas? Perhaps, it doesn't take effect when there are multiple lines on axes? – Rubi Shnol Jun 26 '20 at 14:49