0

[edited as per comments 05-mar-22]

  • I found the problem: the marker point was not scaled to the same units as the x-axis data. I was over thinking it. Thanks for suggesting I try a simple example to recreate. I shouldn't have gotten overwhelmed by the matplotlib man pages. Sorry everyone!

I'm relatively new to Pyplt. I'm having trouble plotting a marker in absolute data coordinates, because at times Pyplt puts the x-axis into relative coordinates about a center value.
In other words, when the x-data min and max are numerically far apart, everything plots as expected. If x-axis min and max are very close together, Pyplot switches to a relative axis mode.
For example, 1.59e3 to 1.61e3 plots as expected. But when the data is from 1.599e3 to 1.601e3 (example), the axis switches from absolute numbers to a relative axis with 0 in the middle, and a label underneath saying 1.60000000e3.
This is fine, and looks great too. But when I try to add a marker in absolute data coordinates, i.e. centred on a data point, the axis goes haywire and goes from 0 to 1.6e9, with the data plotted itself at around 0. The marker ends up in the right place, though.
I see documentation for matplotlib transforms, but it seems to apply only to matlab? Or I'm confused (the most likely issue). Maybe my search-fu is out of whack. How can I deal with the switch to relative axes? [Example relative axes][1]

Avner
  • 1
  • 1
  • Apologies, frequencies (the x-axis) data already scaled to MHz, so 10^3 instead of 10^9 in my example. Sorry to confuse. The question remains the same. – Avner Apr 05 '22 at 16:29
  • Welcome to StackOverflow. The comments aren't meant for corrections. You are supposed to [edit](https://stackoverflow.com/posts/71755304/edit) your post, clarifying everything where possible. Also, you are supposed to add code for a minimal example that reproduces the issue. Especially the phrase *"when I try to add a marker or a label"* needs some example. Note that matplotlib isn't connected to matlab. However, matplotlib started out as an open source alternative to matlab. – JohanC Apr 05 '22 at 17:07
  • See e.g. [Putting text in top left corner of matplotlib plot](https://stackoverflow.com/questions/8482588/putting-text-in-top-left-corner-of-matplotlib-plot) about putting text using "axes coordinates". – JohanC Apr 05 '22 at 17:13
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 05 '22 at 17:18

0 Answers0