Skip to content

Commit

Permalink
fixing overlapping ticks over axis label
Browse files Browse the repository at this point in the history
  • Loading branch information
domarm-comat committed Sep 6, 2023
1 parent b67f0fe commit 2767373
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
9 changes: 7 additions & 2 deletions pglive/examples_pyqt5/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
# Define Time plot
left_axis = LiveAxis("left", axisPen="red", textPen="red")
bottom_axis = LiveAxis("bottom", axisPen="green", textPen="green", tick_angle=-45, **{Axis.TICK_FORMAT: Axis.TIME})
top_axis = LiveAxis("top", axisPen="orange", textPen="orange", tick_angle=-45, **{Axis.TICK_FORMAT: Axis.TIME})
time_axis_plot_widget = LivePlotWidget(title="Time Line Plot @ 100Hz",
axisItems={'bottom': bottom_axis, 'left': left_axis})
axisItems={'bottom': bottom_axis, 'left': left_axis, 'top': top_axis},
labels={'bottom': ("Bottom axis"), 'left': ("Left axis"),
'right': ("Right axis"),
'top': ("Top axis")})
plot = LiveLinePlot()
time_axis_plot_widget.addItem(plot)
connectors.append(DataConnector(plot, max_points=600))
Expand All @@ -33,7 +37,8 @@
left_axis = LiveAxis("left", axisPen="purple", textPen="purple")
bottom_axis = LiveAxis("bottom", axisPen="yellow", textPen="yellow", **{Axis.TICK_FORMAT: Axis.DATETIME})
datetime_axis_plot_widget = LivePlotWidget(title="DateTime Line Plot @ 100Hz",
axisItems={'bottom': bottom_axis, 'left': left_axis})
axisItems={'bottom': bottom_axis, 'left': left_axis},
labels={'bottom': ("Bottom axis"), 'left': ("Left axis")})
plot = LiveLinePlot()
datetime_axis_plot_widget.addItem(plot)

Expand Down
10 changes: 7 additions & 3 deletions pglive/examples_pyqt6/axis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pglive.examples_pyqt6 as examples
import signal
import time
from math import sin
Expand All @@ -7,6 +6,7 @@

import pyqtgraph as pg # type: ignore

import pglive.examples_pyqt6 as examples
from pglive.kwargs import Axis
from pglive.sources.data_connector import DataConnector
from pglive.sources.live_axis import LiveAxis
Expand All @@ -22,8 +22,11 @@
# Define Time plot
left_axis = LiveAxis("left", axisPen="red", textPen="red")
bottom_axis = LiveAxis("bottom", axisPen="green", textPen="green", tick_angle=-45, **{Axis.TICK_FORMAT: Axis.TIME})
top_axis = LiveAxis("top", axisPen="orange", textPen="orange", tick_angle=-45, **{Axis.TICK_FORMAT: Axis.TIME})
time_axis_plot_widget = LivePlotWidget(title="Time Line Plot @ 100Hz",
axisItems={'bottom': bottom_axis, 'left': left_axis})
axisItems={'bottom': bottom_axis, 'left': left_axis, 'top': top_axis},
labels={'bottom': ("Bottom axis"), 'left': ("Left axis"), 'right': ("Right axis"),
'top': ("Top axis")})
plot = LiveLinePlot()
time_axis_plot_widget.addItem(plot)
connectors.append(DataConnector(plot, max_points=600))
Expand All @@ -33,7 +36,8 @@
left_axis = LiveAxis("left", axisPen="purple", textPen="purple")
bottom_axis = LiveAxis("bottom", axisPen="yellow", textPen="yellow", **{Axis.TICK_FORMAT: Axis.DATETIME})
datetime_axis_plot_widget = LivePlotWidget(title="DateTime Line Plot @ 100Hz",
axisItems={'bottom': bottom_axis, 'left': left_axis})
axisItems={'bottom': bottom_axis, 'left': left_axis},
labels={'bottom': ("Bottom axis"), 'left': ("Left axis")})
plot = LiveLinePlot()
datetime_axis_plot_widget.addItem(plot)

Expand Down
11 changes: 8 additions & 3 deletions pglive/examples_pyside6/axis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pglive.examples_pyside6 as examples
import signal
import time
from math import sin
Expand All @@ -7,6 +6,7 @@

import pyqtgraph as pg # type: ignore

import pglive.examples_pyside6 as examples
from pglive.kwargs import Axis
from pglive.sources.data_connector import DataConnector
from pglive.sources.live_axis import LiveAxis
Expand All @@ -22,8 +22,12 @@
# Define Time plot
left_axis = LiveAxis("left", axisPen="red", textPen="red")
bottom_axis = LiveAxis("bottom", axisPen="green", textPen="green", tick_angle=-45, **{Axis.TICK_FORMAT: Axis.TIME})
top_axis = LiveAxis("top", axisPen="orange", textPen="orange", tick_angle=-45, **{Axis.TICK_FORMAT: Axis.TIME})
time_axis_plot_widget = LivePlotWidget(title="Time Line Plot @ 100Hz",
axisItems={'bottom': bottom_axis, 'left': left_axis})
axisItems={'bottom': bottom_axis, 'left': left_axis, 'top': top_axis},
labels={'bottom': ("Bottom axis"), 'left': ("Left axis"),
'right': ("Right axis"),
'top': ("Top axis")})
plot = LiveLinePlot()
time_axis_plot_widget.addItem(plot)
connectors.append(DataConnector(plot, max_points=600))
Expand All @@ -33,7 +37,8 @@
left_axis = LiveAxis("left", axisPen="purple", textPen="purple")
bottom_axis = LiveAxis("bottom", axisPen="yellow", textPen="yellow", **{Axis.TICK_FORMAT: Axis.DATETIME})
datetime_axis_plot_widget = LivePlotWidget(title="DateTime Line Plot @ 100Hz",
axisItems={'bottom': bottom_axis, 'left': left_axis})
axisItems={'bottom': bottom_axis, 'left': left_axis},
labels={'bottom': ("Bottom axis"), 'left': ("Left axis")})
plot = LiveLinePlot()
datetime_axis_plot_widget.addItem(plot)

Expand Down
11 changes: 9 additions & 2 deletions pglive/sources/live_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ def drawPicture(self, p, axisSpec, tickSpecs, textSpecs) -> None:
if self.tick_angle == 0:
for rect, flags, text in textSpecs:
p.drawText(rect, int(flags), text)
if self.label.isVisible():
min_height += self.label.boundingRect().height() * 0.8
self.fixedHeight = min_height + 7
else:
if self.orientation in ("bottom", "top"):
max_height = min_height
offset_top = 0
if self.label.isVisible():
offset_top = self.label.boundingRect().height() * 0.8

for rect, flags, text in textSpecs:
p.save()
if self.orientation == "bottom":
Expand All @@ -133,7 +139,7 @@ def drawPicture(self, p, axisSpec, tickSpecs, textSpecs) -> None:
rot_point = QtCore.QPointF(rect.topRight().x(), rect.center().y())
else:
if 0 < self.tick_angle <= 180:
rect.moveTopLeft(QtCore.QPointF(rect.center().x(), 0))
rect.moveTopLeft(QtCore.QPointF(rect.center().x(), offset_top))
rot_point = QtCore.QPointF(rect.topLeft().x(), rect.center().y())
else:
rect.moveBottomLeft(QtCore.QPointF(rect.center().x(), rect.bottomLeft().y()))
Expand All @@ -150,7 +156,8 @@ def drawPicture(self, p, axisSpec, tickSpecs, textSpecs) -> None:
p.drawText(rect, int(flags), text)
# restoring the painter is *required*!!!
p.restore()
self.fixedHeight = max_height + 10

self.fixedHeight = offset_top + max_height + 10
else:
for rect, flags, text in textSpecs:
p.save()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pglive"
version = "0.7.0"
version = "0.7.1"
description = "Pyqtgraph live plot"
authors = ["Martin Domaracky <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 2767373

Please sign in to comment.