Skip to content

Commit ac22240

Browse files
committed
stupiiid axis override
1 parent a3ba793 commit ac22240

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import pyqtgraph as pg
2+
from pyqtgraph import debug as debug
3+
4+
5+
class AdaptedAxisItem(pg.AxisItem):
6+
def __init__(self, orientation, parent=None,):
7+
pg.AxisItem.__init__(self, orientation, parent=parent)
8+
9+
def drawPicture(self, p, axisSpec, tickSpecs, textSpecs):
10+
profiler = debug.Profiler()
11+
12+
p.setRenderHint(p.Antialiasing, False)
13+
p.setRenderHint(p.TextAntialiasing, True)
14+
15+
# draw long line along axis
16+
pen, p1, p2 = axisSpec
17+
p.setPen(pen)
18+
p.drawLine(p1, p2)
19+
p.translate(0.5, 0) # resolves some damn pixel ambiguity
20+
21+
# draw ticks
22+
for pen, p1, p2 in tickSpecs:
23+
p.setPen(pen)
24+
p.drawLine(p1, p2)
25+
profiler('draw ticks')
26+
27+
# Draw all text
28+
if self.style['tickFont'] is not None:
29+
p.setFont(self.style['tickFont'])
30+
p.setPen(self.textPen())
31+
for rect, flags, text in textSpecs:
32+
p.drawText(rect, int(flags), text)
33+
34+
profiler('draw text')
35+
36+
37+
def replace_axis(plot_item, orientation='left', pos=(2, 0)):
38+
39+
new_axis = AdaptedAxisItem(orientation, parent=plot_item)
40+
oldAxis = plot_item.axes[orientation]['item']
41+
plot_item.layout.removeItem(oldAxis)
42+
oldAxis.unlinkFromView()
43+
#
44+
new_axis.linkToView(plot_item.vb)
45+
plot_item.axes[orientation] = {'item': new_axis, 'pos': pos}
46+
plot_item.layout.addItem(new_axis, *pos)
47+
new_axis.setZValue(-1000)
48+
new_axis.setFlag(new_axis.ItemNegativeZStacksBehindParent)

atlaselectrophysiology/ephys_gui_setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pyqtgraph.exporters
44
import numpy as np
55
from random import randrange
6+
from atlaselectrophysiology.AdaptedAxisItem import replace_axis
67
pg.setConfigOption('background', 'w')
78
pg.setConfigOption('foreground', 'k')
89

@@ -644,6 +645,7 @@ def init_figures(self):
644645
self.fig_hist.setYRange(min=self.probe_tip - self.probe_extra, max=self.probe_top +
645646
self.probe_extra, padding=self.pad)
646647
self.set_axis(self.fig_hist, 'bottom', pen='w')
648+
replace_axis(self.fig_hist)
647649
self.ax_hist = self.set_axis(self.fig_hist, 'left', pen=None)
648650
self.ax_hist.setWidth(0)
649651
self.ax_hist.setStyle(tickTextOffset=-70)
@@ -672,6 +674,7 @@ def init_figures(self):
672674
self.probe_extra, padding=self.pad)
673675
self.set_axis(self.fig_hist_ref, 'bottom', pen='w')
674676
self.set_axis(self.fig_hist_ref, 'left', show=False)
677+
replace_axis(self.fig_hist_ref, orientation='right', pos=(2, 2))
675678
self.ax_hist_ref = self.set_axis(self.fig_hist_ref, 'right', pen=None)
676679
self.ax_hist_ref.setWidth(0)
677680
self.ax_hist_ref.setStyle(tickTextOffset=-70)

0 commit comments

Comments
 (0)