pyqtgraph/examples/utils.py

133 lines
5.1 KiB
Python
Raw Normal View History

from collections import OrderedDict
from argparse import Namespace
examples = OrderedDict([
('Command-line usage', 'CLIexample.py'),
('Basic Plotting', Namespace(filename='Plotting.py', recommended=True)),
('ImageView', 'ImageView.py'),
('ParameterTree', 'parametertree.py'),
('Crosshair / Mouse interaction', 'crosshair.py'),
('Data Slicing', 'DataSlicing.py'),
('Plot Customization', 'customPlot.py'),
Date axis item (#1154) * Add DateAxisItem * Change style to camelCase * Fix missing first tick for negative timestamps * Add ms precision, auto skipping Auto skipping allows a zoom level to skip ticks automatically if the maximum number of ticks/pt is exceeded * fixes suggested by @goetzc * workaround for negative argument to utcfromtimestamp on windows * attachToPlotItem method * default date axis orientation * Use new DateAxisItem in Plot Customization example * attachToPlotItem bugfix * examples of DateAxisItem * modified description of customPlot example * added descriptions to the new examples, reformatted their code, included the first one into utils.py * typo * Refactored code for setting axis items into new function Replaces "DateAxisItem.attachToPlotItem" * Fix string comparison with == * Doc: Slightly more text for DateAxisItem, small improvement for PlotItem * Make PlotWidget.setAxisItems official * Fix typo in docstring * renamed an example * merge bug fix * Revert "merge bug fix" This reverts commit 876b5a7cdb50cd824b4a5218427081b3ce5c2fe4. * Real bug fix * support for dates upto -1e13..1e13 * Automatically limit DateAxisItem to a range from -1e12 to 1e12 years Very large years (|y|>1e13) cause infinite loop, and since nobody needs time 100 times larger than the age of the universe anyways, this constrains it to 1e12. Following suggestion by @axil: https://github.com/pyqtgraph/pyqtgraph/pull/1154#issuecomment-612662168 * Also catch ValueErrors occuring on Linux before OverfloeErrors While zooming out, before hitting OverflowErrors, utctimestamp produces ValueErrors (at least on my Linux machine), so they are also catched. * Fix: Timestamp 0 corresponds to year 1970 For large years, x axis labels jump by 1970 years if it is not accounted for timestamp 0 to be equal to year 1970. * Fix: When zooming into extreme dates, OSError occurs This commit catches the OSError like the other observed errors * Disable stepping below years for dates outside *_REGULAR_TIMESTAMP 2 reasons: First: At least on my Linux machine, zooming into those dates creates infinite loops. Second: Nobody needs sub-year-precision for those extreme years anyways. * Adapt zoom level sizes based on current font size and screen resolution This is somewhat experimental. With this commit, no longer 60 px are assumed as width for all zoom levels, but the current font and display resolution are considered to calculate the width of ticks in each zoom level. See the new function `updateZoomLevels` for details. Before calling this function, overridden functions `paint` and `generateDrawSpecs` provide information over the current display and font via `self.fontScaleFactor` and `self.fontMetrics`. * Meaningful error meassage when adding axis to multiple PlotItems As @axil noted in the DateAxisItem PR, currently users get a segmentation fault when one tries to add an axis to multiple PlotItems. This commit adds a meaningful RuntimeError message for that case. * setZoomLevelForDensity: Refactoring and calculating optimal spacing on the fly * DateTimeAxis Fix: 1970 shows when zooming far out * Refactoring: Make zoomLevels a customizable dict again * updated the dateaxisitem example * Fix: Get screen resolution in a way that also works for Qt 4 This is both a simplification in code and an improvement in backwards compatibility with Qt 4. * DateAxisItem Fix: Also resolve time below 0.5 seconds * unix line endings in examples * DateTimeAxis Fix: For years < 1 and > 9999, stepping broke Stepping was off by 1970 years for years < 1 and > 9999, resulting in a gap in ticks visible when zooming out. Fixed by subtracting the usual 1970 years. * DateTimeAxis Fix: Zooming out too far causes infinite loop Fixed by setting default limits to +/- 1e10 years. Should still be enough. * improved second dateaxisitem example * 1..9999 years limit * DateTimeAxis: Use OrderedDict to stay compatible with Python < 3-6 * DateAxisItem: Use font height to determine spacing for vertical axes * window title * added dateaxisitem.rst * updated index.rst Co-authored-by: Lukas Heiniger <lukas.heiniger@sed.ethz.ch> Co-authored-by: Lev Maximov <lev.maximov@gmail.com> Co-authored-by: 2xB <2xB@users.noreply.github.com>
2020-04-27 18:43:22 +00:00
('Timestamps on x axis', 'DateAxisItem.py'),
('Image Analysis', 'imageAnalysis.py'),
('Matrix Display', 'MatrixDisplayExample.py'),
('ViewBox Features', Namespace(filename='ViewBoxFeatures.py', recommended=True)),
('Dock widgets', 'dockarea.py'),
('Console', 'ConsoleWidget.py'),
('Histograms', 'histogram.py'),
('Beeswarm plot', 'beeswarm.py'),
('Symbols', 'Symbols.py'),
('Auto-range', 'PlotAutoRange.py'),
('Remote Plotting', 'RemoteSpeedTest.py'),
('Scrolling plots', 'scrollingPlots.py'),
('HDF5 big data', 'hdf5.py'),
('Demos', OrderedDict([
('Optics', 'optics_demos.py'),
('Special relativity', 'relativity_demo.py'),
('Verlet chain', 'verlet_chain_demo.py'),
2017-10-18 07:26:37 +00:00
('Koch Fractal', 'fractal.py'),
])),
('Colors', OrderedDict([
('Color Maps', 'colorMaps.py'),
('Color Map Linearization', 'colorMapsLinearized.py'),
('Color Gradient Plots', 'ColorGradientPlots.py'),
('Palette demonstration','PaletteDemonstration.py'),
('Palette editor','PaletteEditor.py'),
])),
('GraphicsItems', OrderedDict([
('Scatter Plot', 'ScatterPlot.py'),
#('PlotItem', 'PlotItem.py'),
('InfiniteLine', 'InfiniteLine.py'),
('IsocurveItem', 'isocurve.py'),
('GraphItem', 'GraphItem.py'),
('ErrorBarItem', 'ErrorBarItem.py'),
('FillBetweenItem', 'FillBetweenItem.py'),
('ImageItem - video', 'ImageItem.py'),
('ImageItem - draw', 'Draw.py'),
('ColorBarItem','ColorBarItem.py'),
('Non-uniform Image', 'NonUniformImage.py'),
('Region-of-Interest', 'ROIExamples.py'),
('Bar Graph', 'BarGraphItem.py'),
('GraphicsLayout', 'GraphicsLayout.py'),
('LegendItem', 'Legend.py'),
('Text Item', 'text.py'),
('Linked Views', 'linkedViews.py'),
('Arrow', 'Arrow.py'),
2018-07-10 12:56:35 +00:00
('ViewBox', 'ViewBoxFeatures.py'),
('Custom Graphics', 'customGraphicsItem.py'),
('Labeled Graph', 'CustomGraphItem.py'),
2020-07-15 08:30:41 +00:00
('PColorMeshItem', 'PColorMeshItem.py'),
])),
('Benchmarks', OrderedDict([
('Video speed test', 'VideoSpeedTest.py'),
('Line Plot update', 'PlotSpeedTest.py'),
('Scatter Plot update', 'ScatterPlotSpeedTest.py'),
('Multiple plots', 'MultiPlotSpeedTest.py'),
])),
('3D Graphics', OrderedDict([
('Volumetric', 'GLVolumeItem.py'),
('Isosurface', 'GLIsosurface.py'),
('Surface Plot', 'GLSurfacePlot.py'),
('Scatter Plot', 'GLScatterPlotItem.py'),
('Shaders', 'GLshaders.py'),
('Line Plot', 'GLLinePlotItem.py'),
('Mesh', 'GLMeshItem.py'),
('Image', 'GLImageItem.py'),
Add "GLTextItem" (#1776) * Add GLTextItem * Fixed DocString. * Delete unnecessary function. * Add `from .items.GLTextItem import *` * Add an example. * [Combines two `isinstance()` into one.](https://github.com/pyqtgraph/pyqtgraph/pull/1776#discussion_r633046120) * [Combines two `isinstance()` into one.](https://github.com/pyqtgraph/pyqtgraph/pull/1776#discussion_r633046120) * [The long code has been broken up into separate lines.](https://github.com/pyqtgraph/pyqtgraph/pull/1776#discussion_r633046234) * [Moved `pos`, `color`, `text`, and `font` to the `__init__` method.](https://github.com/pyqtgraph/pyqtgraph/pull/1776#discussion_r633047216) * Add `import initExample` and fix `mkQApp().exec_()` to `pg.exec()` (https://github.com/pyqtgraph/pyqtgraph/pull/1776#discussion_r633046878, https://github.com/pyqtgraph/pyqtgraph/pull/1776#discussion_r633046781) * Fix `pg.exec()` to `pg.mkQApp().exec()` * Revert "Fix `pg.exec()` to `pg.mkQApp().exec()`" This reverts commit 67d397d8033f3fe0cc27468ea96fe61dc29cc78b. * Remove type-hints. * Fix `glColor4d(float(self.color[0]), float(self.color[1]), float(self.color[2]), float(self.color[3]))` to `glColor4d(*self.color)` * Add `value = fn.glColor(value)` * Remove debug print. * Add GLGridItem and GLAxisItem * Remove if-check for "color" argument * Draw text without using GLUT. * Divide the text position by the device pixel ratio * Fixed bare exceptions to ValueError and TypeError. * Add 'GLTextItem.py' to utils.py. * Fixed a bare exception to ArgumentErrror. * Add `__all__ = ['GLTextItem']`
2021-06-05 15:19:54 +00:00
('Text', 'GLTextItem.py'),
])),
('Widgets', OrderedDict([
('PlotWidget', 'PlotWidget.py'),
('SpinBox', 'SpinBox.py'),
('ConsoleWidget', 'ConsoleWidget.py'),
('Histogram / lookup table', 'HistogramLUT.py'),
('TreeWidget', 'TreeWidget.py'),
('ScatterPlotWidget', 'ScatterPlotWidget.py'),
('DataTreeWidget', 'DataTreeWidget.py'),
('GradientWidget', 'GradientWidget.py'),
('TableWidget', 'TableWidget.py'),
('ColorButton', 'ColorButton.py'),
#('CheckTable', '../widgets/CheckTable.py'),
#('VerticalLabel', '../widgets/VerticalLabel.py'),
('JoystickButton', 'JoystickButton.py'),
])),
('Flowcharts', 'Flowchart.py'),
('Custom Flowchart Nodes', 'FlowchartCustomNode.py'),
])
# don't care about ordering
# but actually from Python 3.7, dict is ordered
others = dict([
('logAxis', 'logAxis.py'),
('PanningPlot', 'PanningPlot.py'),
('MultiplePlotAxes', 'MultiplePlotAxes.py'),
('ROItypes', 'ROItypes.py'),
('ScaleBar', 'ScaleBar.py'),
('ViewBox', 'ViewBox.py'),
('GradientEditor', 'GradientEditor.py'),
('GLBarGraphItem', 'GLBarGraphItem.py'),
('GLViewWidget', 'GLViewWidget.py'),
('DiffTreeWidget', 'DiffTreeWidget.py'),
('MultiPlotWidget', 'MultiPlotWidget.py'),
('RemoteGraphicsView', 'RemoteGraphicsView.py'),
('contextMenu', 'contextMenu.py'),
('designerExample', 'designerExample.py'),
('DateAxisItem_QtDesigner', 'DateAxisItem_QtDesigner.py'),
('GraphicsScene', 'GraphicsScene.py'),
('MouseSelection', 'MouseSelection.py'),
])
# examples that are subsumed into other examples
trivial = dict([
('SimplePlot', 'SimplePlot.py'), # Plotting.py
('LogPlotTest', 'LogPlotTest.py'), # Plotting.py
('ViewLimits', 'ViewLimits.py'), # ViewBoxFeatures.py
])
2021-02-06 08:58:17 +00:00
# examples that are not suitable for CI testing
skiptest = dict([
('ProgressDialog', 'ProgressDialog.py'), # modal dialog
])