均線Color設定:
先說結論: pg.plot(xdata, ydata, pen='r')
1. 參考資訊1:
https://www.geeksforgeeks.org/pyqtgraph-setting-pen-of-line-in-line-graph/
# method for components
def
UiComponents(
self
):
# creating a widget object
widget
=
QWidget()
# creating a new label
label
=
QLabel(
"GeeksforGeeks Line Plot"
)
# making it multiline
label.setWordWrap(
True
)
# y values to plot by line 1
y
=
[
2
,
8
,
6
,
8
,
6
,
11
,
14
,
13
,
18
,
19
]
# y values to plot by line 2
y2
=
[
3
,
1
,
5
,
8
,
9
,
11
,
16
,
17
,
14
,
16
]
x
=
range
(
0
,
10
)
# create plot window object
plt
=
pg.plot()
# showing x and y grids
plt.showGrid(x
=
True
, y
=
True
)
# adding legend
plt.addLegend()
# set properties of the label for y axis
plt.setLabel(
'left'
,
'Vertical Values'
, units
=
'y'
)
# set properties of the label for x axis
plt.setLabel(
'bottom'
,
'Horizontal Values'
, units
=
's'
)
# setting horizontal range
plt.setXRange(
0
,
10
)
# setting vertical range
plt.setYRange(
0
,
20
)
# plotting line in green color
# with dot symbol as x, not a mandatory field
line1
=
plt.plot(x, y, pen
=
'g'
, symbol
=
'x'
, symbolPen
=
'g'
, symbolBrush
=
0.2
, name
=
'green'
)
# plotting line2 with blue color
# with dot symbol as o
line2
=
plt.plot(x, y2, pen
=
'b'
, symbol
=
'o'
, symbolPen
=
'b'
, symbolBrush
=
0.2
, name
=
'blue'
)
# setting pen of the line 1
line1.setPen(QColor(
168
,
34
,
3
))
2. 參考資訊2:
Line, Fill, and Color
Qt relies on its QColor, QPen and QBrush classes for specifying line and fill styles for all of its drawing.
Internally, pyqtgraph uses the same system but also allows many shorthand methods of specifying the same style options.
Many functions and methods in pyqtgraph accept arguments specifying the line style (pen), fill style (brush), or color. For most of these function arguments, the following values may be used:
single-character string representing color (b, g, r, c, m, y, k, w)
(r, g, b) or (r, g, b, a) tuple
single greyscale value (0.0 - 1.0)
(index, maximum) tuple for automatically iterating through colors (see intColor
)
QColor
QPen / QBrush where appropriate
Notably, more complex pens and brushes can be easily built using the mkPen()
/ mkBrush()
functions or with Qt’s QPen and QBrush classes:
mkPen('y', width=3, style=QtCore.Qt.DashLine) ## Make a dashed yellow line 2px wide
mkPen(0.5) ## solid grey line 1px wide
mkPen(color=(200, 200, 255), style=QtCore.Qt.DotLine) ## Dotted pale-blue line
See the Qt documentation for ‘QPen’ and ‘PenStyle’ for more line-style options and ‘QBrush’ for more fill options. Colors can also be built using mkColor()
, intColor()
, hsvColor()
, or Qt’s QColor class.
Default Background and Foreground Colors
By default, pyqtgraph uses a black background for its plots and grey for axes, text, and plot lines. These defaults can be changed using pyqtgraph.setConfigOption():
import pyqtgraph as pg
## Switch to using white background and black foreground
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
## The following plot has inverted colors
pg.plot([1,4,2,3,5])
(Note that this must be set before creating any widgets)
3. 參考資訊3:
https://www.geeksforgeeks.org/pyqtgraph-setting-background-of-plot-window/
# create pyqt5graph bar graph item
# with width = 0.6
# with bar colors = green
bargraph1
=
pg.BarGraphItem(x
=
x, height
=
y1, width
=
0.6
, brush
=
'g'
)
# add item to plot window
# adding bargraph item to the window
window.addItem(bargraph1)
# setting plot window background color to yellow
window.setBackground(
'y'
)
4. 參考資訊4: (成功)
https://pyqtgraph.readthedocs.io/en/latest/api_reference/functions.html#pyqtgraph.mkPen
Color, Pen, and Brush Functions
Qt uses the classes QColor, QPen, and QBrush to determine how to draw lines and fill shapes. These classes are highly capable but somewhat awkward to use. PyQtGraph offers the functions mkColor()
, mkPen()
, and mkBrush()
to simplify the process of creating these classes. In most cases, however, it will be unnecessary to call these functions directly–any function or method that accepts pen or brush arguments will make use of these functions for you.
For example, the following three lines all have the same effect:
沒有留言:
張貼留言