macos Big Sur matplotlib chart displaying extra data, while Windows, Linux Mint working properly

29 Views Asked by At

Pls help, I'm desperate and behind schedule , I've tried to solve this over 1 week for a solution but nothing! I have been working on a relatively simple cross platform python app. This app works correctly in Windows 10/11 and Linux Mint but not in MacOS, Big Sur. The app uses matplotlib + tkinter to display an animated chart, updated every 1 second, with live data yanked from the OS (wireless signal strength)

I have used the following commands code to suppress any X-axis labeling-

ax.tick_params(reset=True)
ax.tick_params('y', left=False, right=False, bottom=False, labelsize=8)
ax.tick_params('x', labelbottom=False, bottom=False, top=False)

This code properly ensures no data is displayed on x-axis (as expected) on Windows 10, 11, Linux Mint, BUT on MacOS Big Sur (11.7) it displays the latest/newest x-axis, x value on the extreme rhs of the chart, basically only labeling the newest data value of the x-axis. See image below, the number in the red dashed rectangle shouldn't display.

macos displaying plot incorrectly

Interestingly I was able to recreate the same issue for all OS's by changing the above lines to the following code:

ax.tick_params('x', labelbottom=False, bottom=False,reset=True)
ax.tick_params('y', left=False, right=False, bottom=False, labelsize=8)

PS I did see the issue with macos backends and using the framework version, my understanding is that I am using the Macos "framework version": pythonw on the macos installed thru anaconda

1

There are 1 best solutions below

5
chrslg On

It looks a lot like an offset rather than the newest value to me. Have you tried to

ax.xaxis.get_major_formatter().set_useOffset(False)

Just to see if it changes something (or even solve the problem)?

Another thing you could try, in case it is really a label, not an offset, is to specify a formatter

import matplotlib.ticker as ticker
ax.xaxis.set_major_formatter(ticker.NullFormatter())

or

ax.xaxis.set_major_formatter(ticker.FormatStrFormatter("tick"))

This last one, is a test to check if this is really ticks. If you only see "tick", you can try to solve the problem (bypass it, rather) by

ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(" "))

(Tho, if this works, then NullFormatter should have work either. But, hard to say what works in a situation where none of that should have been necessary anyway)