fix magnitude of limits in case of a single value - #1233
Conversation
|
This might be the proper fix: @@ -2098,11 +2098,11 @@ def insertYMarker(self, y, legend=None, text=None,
xmin, xmax = self.getGraphXLimits()
delta = abs(xmax - xmin)
if xmin > xmax:
xmax = xmin
xmax -= 0.005 * delta
- line._infoText = self.ax.text(y, xmax, text,
+ line._infoText = self.ax.text(xmax, y, text,
color=color,
horizontalalignment='left',
verticalalignment='top')
line._plot_options = ["ymarker"]
if selectable: |
|
MRE to reproduce the bug with PyMca's MatplotlibBackend from PyMca5.PyMcaGraph.backends.MatplotlibBackend import MatplotlibBackend
V = 1e10
backend = MatplotlibBackend()
backend.setLimits(0, 1024, V, V)
backend.insertYMarker(V, text="marker")
backend.ax.get_figure().canvas.draw()
print("OK")The fix in #1233 (comment) solves it. |
|
I have data which is 1x1000x1000 -> ROI image -> select "1D data is first dimension" It a strange thing to do... but user found it |
|
The full error message: Error |
|
Sorry I cannot reproduce import sys
import h5py
import numpy as np
from PyQt5.QtWidgets import QApplication
from PyMca5.PyMcaGui.pymca.QStackWidget import QStackWidget
from PyMca5.PyMcaCore import StackBase
from PyMca5.PyMcaCore import DataObject
filename = "test_stack.h5"
with h5py.File(filename, "w") as f:
f.create_dataset(
"data",
shape=(1, 1000, 1000),
dtype=np.float32
)
app = QApplication(sys.argv)
w = QStackWidget()
w.show()
stack = DataObject.DataObject()
with h5py.File(filename, "r") as f:
stack.data = f["data"][()]
# "1D data is first dimension"
stack.info = {
"McaIndex": 0,
"SourceType": "HDF5"
}
w.setStack(stack)
sys.exit(app.exec())The reason I'm insisting to understand what the problem is exactly is the magic |
|
part of the problem is that in particular it lead to overflow of pixel dimension (see the the end of original error) , which crush the positioning of the So to reproduce the problem - (1) bad range + (2) use position. try to set data like |
| if vmin != vmax: | ||
| return vmin, vmax | ||
| # magnitude problem; necessary for matplotlib >= 3.11 | ||
| delta = max(0.044, abs(vmin) * 0.05) |
There was a problem hiding this comment.
Now I finally understand what the problem is
>>> numpy.float32(1e10) == (numpy.float32(1e10) + 0.044)
np.True_
This code tries to ensure that xmin != xmax.
Since this depends on the float-precision the delta must be relative not absolute.
We keep the magic 0.044 is a lower bound.
Ok I'm fine with this.
a strange bug appears in
modulebecause it usesmatplotlib==3.11.0minimal reproduction of an issue:
tested on 3.10, 3.11.0, 3.11.1