The following code snippet and plot shows how Matplotlib's markevery
keyword can be convenient for placing markers on line without cluttering the plot by marking every point in a large dataset. Is there a similar feature in PyQtGraph, or do I just have to call plot twice to put symbols on a subset of the data?
from matplotlib import pyplot as plt
import pyqtgraph as pg
import numpy as np
x = np.linspace(0, 10, 151)
y = x**2
pg.plot(x, y, symbol='o')
plt.plot(x, y, marker='o')
plt.plot(x, y+10, marker='o', markevery=10)
plt.show()
If this keyword does not exist in pyqtgraph, you could simply use the following code instead:
pg.plot([j for i, j in enumerate(x) if i%10==0], [j for i, j in enumerate(y) if i%10==0], symbol='o')
where you could replace i%10==0
with i%z==0
, where z
is equivalent to the markevery
integer.
--or--
def pg_markevery(arr, markevery):
return [j for i, j in enumerate(arr) if i%markevery==0]
pg.plot(pg_markevery(x, markevery=10), pg_markevery(y, markevery=10), symbol='o')