2012-10-22 18:10:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
In this example we draw two different kinds of histogram.
|
|
|
|
"""
|
|
|
|
import initExample ## Add path to library (just for examples; you do not need this)
|
|
|
|
|
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
|
|
|
import numpy as np
|
|
|
|
|
2018-02-16 04:15:32 +00:00
|
|
|
win = pg.GraphicsLayoutWidget(show=True)
|
2012-10-22 18:10:16 +00:00
|
|
|
win.resize(800,350)
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: Histogram')
|
2012-10-22 18:10:16 +00:00
|
|
|
plt1 = win.addPlot()
|
|
|
|
plt2 = win.addPlot()
|
|
|
|
|
|
|
|
## make interesting distribution of values
|
|
|
|
vals = np.hstack([np.random.normal(size=500), np.random.normal(size=260, loc=4)])
|
|
|
|
|
2013-02-25 04:09:03 +00:00
|
|
|
## compute standard histogram
|
2012-10-22 18:10:16 +00:00
|
|
|
y,x = np.histogram(vals, bins=np.linspace(-3, 8, 40))
|
|
|
|
|
Add "left" and "right" step Modes (#1360)
* Add "lstep" and "rstep" step Modes
stepMode is currently either True or False. If it is True,
it requires the user to make len(x) = len(y)+1. This is
inconvenient because it makes it difficult to change the
stepMode on a given curve (just as one would change, e.g.,
its color).
This commit extends the current situation by introducing
two more step modes: "lstep" and "rstep", which do not require
passing an extra x value. In turn, this modes associate each
y value to either the left or the right boundary of the step.
For example, the "rstep" mode is handy when plotting "life"
digital signals in which x,y data pairs are appended as they
are read.
This commit does not modify the behaviour in case of stepMode=True
* Replace step mode names: lstep,rstep -> left,right
* Improve docs for stepMode
Reword docstring and add it to PlotDataItem class too
* Document left and right stepModes as added in v 0.12.0
TODO: confirm the exact version number to use here
* Add comments stress the need for "is True"
Some conditional statements in the code regarding stepMode are
done with "is True". This is actually required since other
possible values such as "left" also evaluate as true but should
not be caught.
* Deprecate boolean API for stepMode
Introduce stepMode="mid" as a replacement of stepMode=True,
but keeping full backwards compatibility with the old API.
Adapt docs, examples and tests accordingly.
* Raise ValueError on unsupported stepMode values
* Rename "mid" step mode to "center"
* Remove "added in 0.12.0" note
See https://github.com/pyqtgraph/pyqtgraph/pull/1360#discussion_r502746919
* Add deprecation warning when stepMode=True
Issue a DeprecationWarning if stepMode=True is being passed to the
constructor or setData() of PlotDataItem or PlotCurveItem.
Note: warnings module is imported locally so that it is esier to
remove once this check is no longer needed.
* Fix wrong syntax in last commit
Fix usage of "default" kwarg in dict.get()
2020-10-13 15:52:07 +00:00
|
|
|
## Using stepMode="center" causes the plot to draw two lines for each sample.
|
2012-10-22 18:10:16 +00:00
|
|
|
## notice that len(x) == len(y)+1
|
Add "left" and "right" step Modes (#1360)
* Add "lstep" and "rstep" step Modes
stepMode is currently either True or False. If it is True,
it requires the user to make len(x) = len(y)+1. This is
inconvenient because it makes it difficult to change the
stepMode on a given curve (just as one would change, e.g.,
its color).
This commit extends the current situation by introducing
two more step modes: "lstep" and "rstep", which do not require
passing an extra x value. In turn, this modes associate each
y value to either the left or the right boundary of the step.
For example, the "rstep" mode is handy when plotting "life"
digital signals in which x,y data pairs are appended as they
are read.
This commit does not modify the behaviour in case of stepMode=True
* Replace step mode names: lstep,rstep -> left,right
* Improve docs for stepMode
Reword docstring and add it to PlotDataItem class too
* Document left and right stepModes as added in v 0.12.0
TODO: confirm the exact version number to use here
* Add comments stress the need for "is True"
Some conditional statements in the code regarding stepMode are
done with "is True". This is actually required since other
possible values such as "left" also evaluate as true but should
not be caught.
* Deprecate boolean API for stepMode
Introduce stepMode="mid" as a replacement of stepMode=True,
but keeping full backwards compatibility with the old API.
Adapt docs, examples and tests accordingly.
* Raise ValueError on unsupported stepMode values
* Rename "mid" step mode to "center"
* Remove "added in 0.12.0" note
See https://github.com/pyqtgraph/pyqtgraph/pull/1360#discussion_r502746919
* Add deprecation warning when stepMode=True
Issue a DeprecationWarning if stepMode=True is being passed to the
constructor or setData() of PlotDataItem or PlotCurveItem.
Note: warnings module is imported locally so that it is esier to
remove once this check is no longer needed.
* Fix wrong syntax in last commit
Fix usage of "default" kwarg in dict.get()
2020-10-13 15:52:07 +00:00
|
|
|
plt1.plot(x, y, stepMode="center", fillLevel=0, fillOutline=True, brush=(0,0,255,150))
|
2012-10-22 18:10:16 +00:00
|
|
|
|
|
|
|
## Now draw all points as a nicely-spaced scatter plot
|
|
|
|
y = pg.pseudoScatter(vals, spacing=0.15)
|
2014-04-12 22:01:50 +00:00
|
|
|
#plt2.plot(vals, y, pen=None, symbol='o', symbolSize=5)
|
|
|
|
plt2.plot(vals, y, pen=None, symbol='o', symbolSize=5, symbolPen=(255,255,255,200), symbolBrush=(0,0,255,150))
|
2012-10-22 18:10:16 +00:00
|
|
|
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
2021-05-13 21:28:22 +00:00
|
|
|
pg.exec()
|