CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
AxisItem_label_overlap.py75 linesDownload Raw Back to examples
1"""2This example demonstrates many of the 2D plotting capabilities3in pyqtgraph. All of the plots may be panned/scaled by dragging with 4the left/right mouse buttons. Right click on any plot to show a context menu.5"""6 7import numpy as np8 9import pyqtgraph as pg10from pyqtgraph.Qt import QtGui11 12app = pg.mkQApp("AxisItem - label overlap settings")13 14win = pg.GraphicsLayoutWidget(show=True, title="AxisItem - label overlap settings")15win.resize(800,600)16win.setWindowTitle("AxisItem - label overlap settings")17 18# Enable antialiasing for prettier plots19pg.setConfigOptions(antialias=True)20 21x_data = np.arange(101) + 1_000.22y_data = np.random.normal(scale=40., size=101)23 24font = QtGui.QFont()25font.setPointSize(14) # A larger font makes the effects more visible26 27p1 = win.addPlot(title="Default settings: Overlap allowed for y axis", x=x_data, y=y_data)28for axis_key in ('top', 'bottom', 'left', 'right'):29    ax = p1.getAxis(axis_key)30    ax.setTickFont( font )31 32p2 = win.addPlot(title="Overlap allowed for X axis", x=x_data, y=y_data)33for axis_key, hide_overlap in (34    ('top'   , False), 35    ('bottom', False),36    ('left'  , True ),37    ('right' , True )38):39    ax = p2.getAxis(axis_key)40    ax.setStyle( hideOverlappingLabels = hide_overlap )41    ax.setTickFont( font )42 43win.nextRow()44 45p3 = win.addPlot(title="All overlap disabled", x=x_data, y=y_data)46for axis_key in ('top', 'bottom', 'left', 'right'):47    ax = p3.getAxis(axis_key)48    ax.setStyle( hideOverlappingLabels = True )49    ax.setTickFont( font )50 51p4 = win.addPlot(title="All overlap enabled, custom tolerances", x=x_data, y=y_data)52for axis_key, tolerance in (53    ('top'   ,  15 ),54    ('bottom', 200 ),55    ('left'  , 100 ),56    ('right' ,  15 )57):58    ax = p4.getAxis(axis_key)59    ax.setStyle( hideOverlappingLabels = tolerance )60    ax.setTickFont( font )61 62# Link all axes and set viewing range with no padding:63for p in (p1, p2, p3, p4):64    p.showAxes(True, showValues=(True, True, True, True))65    if p != p1:66        p.setXLink(p1)67        p.setYLink(p1)68    ax.setTickFont( font )69p1.setXRange( 1_000., 1_100., padding=0.0)70p1.setYRange(-60.,  60., padding=0.0)71 72 73if __name__ == '__main__':74    pg.exec()75 
Aluode/PerceptionLabPortable · CoolFace