Error when placing markers at specific points using matplotlib and markevery

I want to place markers on specific lines. I have a TRUE / FALSE list that says where on the x-axis the markers are needed. Here is the snippet I'm using:

markers_on = list(compress(self.x, self.titanic1))
a0.plot(self.x, self.nya, marker='v', markevery=markers_on)

      

self.titanic1 is a list of boolean values, self.x is a list of our x-axis values, and self.nya is a list of y-values. I am getting the following error.

error message

The interesting bit is that the list in the error message is correct, these are the correct x-axis values ​​for the markers. Does anyone know what this message means? Markevery doc clearly says it will take a list of integers.

markevery   [None | int | length-2 tuple of int | slice | list/array of int | float | length-2 tuple of float]

      

+3


source to share


2 answers


If the list specified in markevery

is a list of integers, it is interpreted as a list of indices for the marked values.

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0,1,0.2)
y = np.random.rand(len(x))

boolean= [True, False, False, True, True]
mark = list(np.arange(len(x))[boolean])

plt.plot(x,y, marker="o", markevery=mark)

plt.show()

      



However, note that you can directly provide a list of booleans formarkevery

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0,1,0.2)
y = np.random.rand(len(x))

boolean= [True, False, False, True, True]

plt.plot(x,y, marker="o", markevery=boolean)

plt.show()

      

+2


source


So I figured it out to draw only the markers. (I build the line before.)

markers_x = list(compress(self.x, self.titanic1))
markers_y = list(compress(self.nya, self.titanic1))
markers_y = [i * 1.01 for i in markers_y] # shift the markers up a bit
t1, = a0.plot(markers_x, markers_y, 'bv') # pass t1 later for legend

      



But I would still like to know what this error message means in case anyone has a hint or trailhead.

+1


source







All Articles