Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/silx/gui/plot/backends/BackendMatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,23 @@ def __init__(self, plot, parent=None):
self.ax = self.fig.add_axes([0.15, 0.15, 0.75, 0.75], label="left")
self.ax2 = self.ax.twinx()
self.ax2.set_label("right")

xOffsetText = self.ax.xaxis.get_offset_text()
xOffsetText.set_weight("heavy")
xOffsetText.set_fontsize(1.1 * xOffsetText.get_fontsize())

self.ax.yaxis.OFFSETTEXTPAD = 10
yOffsetText = self.ax.yaxis.get_offset_text()
yOffsetText.set_weight("heavy")
yOffsetText.set_fontsize(1.1 * yOffsetText.get_fontsize())
yOffsetText.set_ha("right")

self.ax2.yaxis.OFFSETTEXTPAD = 10
y2OffsetText = self.ax2.yaxis.get_offset_text()
y2OffsetText.set_weight("heavy")
y2OffsetText.set_fontsize(1.1 * y2OffsetText.get_fontsize())
y2OffsetText.set_ha("left")

# Make sure background of Axes is displayed
self.ax2.patch.set_visible(False)
self.ax.patch.set_visible(True)
Expand Down
50 changes: 33 additions & 17 deletions src/silx/gui/plot/backends/glutils/GLPlotFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(
self._foregroundColor = foregroundColor
self._labelAlign = labelAlign
self._labelVAlign = labelVAlign
self._orderOffetAnchor = (1.0, 0.0)
self._orderOffsetAnchor = (1.0, 0.0)
self._orderOffsetAlign = orderOffsetAlign
self._orderOffsetVAlign = orderOffsetVAlign
self._titleAlign = titleAlign
Expand Down Expand Up @@ -211,14 +211,14 @@ def title(self, title):
self._dirtyPlotFrame()

@property
def orderOffetAnchor(self) -> tuple[float, float]:
def orderOffsetAnchor(self) -> tuple[float, float]:
"""Anchor position for the tick order&offset text"""
return self._orderOffetAnchor
return self._orderOffsetAnchor

@orderOffetAnchor.setter
def orderOffetAnchor(self, position: tuple[float, float]):
if position != self._orderOffetAnchor:
self._orderOffetAnchor = position
@orderOffsetAnchor.setter
def orderOffsetAnchor(self, position: tuple[float, float]):
if position != self._orderOffsetAnchor:
self._orderOffsetAnchor = position
self._dirtyTicks()

@property
Expand Down Expand Up @@ -315,21 +315,37 @@ def getVerticesAndLabels(self):
labels.append(axisTitle)

if self._orderAndOffsetText:
xOrderOffset, yOrderOffet = self.orderOffetAnchor
orderAndOffsetFont = self._orderAndOffsetFont(self.font)

xOrderOffset, yOrderOffset = self.orderOffsetAnchor
labels.append(
Text2D(
text=self._orderAndOffsetText,
font=self.font,
font=orderAndOffsetFont,
color=self._foregroundColor,
x=xOrderOffset,
y=yOrderOffet,
y=yOrderOffset,
align=self._orderOffsetAlign,
valign=self._orderOffsetVAlign,
devicePixelRatio=self.devicePixelRatio,
)
)
return vertices, labels

@staticmethod
def _orderAndOffsetFont(font: qt.QFont) -> qt.QFont:
"""Returns a larger bold font"""
boldBiggerFont = qt.QFont(font)
boldBiggerFont.setWeight(qt.QFont.ExtraBold)
# Increase font size which is either in pixel or in points
pointSize = boldBiggerFont.pointSizeF()
if pointSize > 0:
boldBiggerFont.setPointSizeF(1.1 * pointSize)
pixelSize = boldBiggerFont.pixelSize()
if pixelSize > 0:
boldBiggerFont.setPixelSize(int(1.1 * pixelSize))
return boldBiggerFont

def _dirtyPlotFrame(self):
"""Dirty parent GLPlotFrame"""
plotFrame = self._plotFrameRef()
Expand Down Expand Up @@ -856,7 +872,7 @@ def __init__(self, marginRatios, foregroundColor, gridColor, font: qt.QFont):
foregroundColor=self._foregroundColor,
labelAlign=RIGHT,
labelVAlign=CENTER,
orderOffsetAlign=LEFT,
orderOffsetAlign=RIGHT,
orderOffsetVAlign=BOTTOM,
titleAlign=CENTER,
titleVAlign=BOTTOM,
Expand All @@ -871,7 +887,7 @@ def __init__(self, marginRatios, foregroundColor, gridColor, font: qt.QFont):
foregroundColor=self._foregroundColor,
labelAlign=LEFT,
labelVAlign=CENTER,
orderOffsetAlign=RIGHT,
orderOffsetAlign=LEFT,
orderOffsetVAlign=BOTTOM,
titleAlign=CENTER,
titleVAlign=TOP,
Expand Down Expand Up @@ -1364,17 +1380,17 @@ def _buildVerticesAndLabels(self):
if fontPixelSize == -1:
fontPixelSize = self._font.pointSizeF() / 72.0 * self.dotsPerInch

self.axes[0].orderOffetAnchor = (
self.axes[0].orderOffsetAnchor = (
xRight,
yBottom + fontPixelSize * 1.2,
)
self.axes[1].orderOffetAnchor = (
self.axes[1].orderOffsetAnchor = (
xLeft,
yTop - 4 * self.devicePixelRatio,
yTop - 4 * self.devicePixelRatio - fontPixelSize / 2.0,
)
self._y2Axis.orderOffetAnchor = (
self._y2Axis.orderOffsetAnchor = (
xRight,
yTop - 4 * self.devicePixelRatio,
yTop - 4 * self.devicePixelRatio - fontPixelSize / 2.0,
)

if self.isYAxisInverted:
Expand Down
Loading