FourierFlux
FourierFlux

Reputation: 599

Adding error bar to scatter plot, existing examples don't work

Hello I am trying to add an error bar to the following scatter plot:

(x, y) = self.rig_parameters["image_size"]
        
disparity_image = np.array(image)

locations = np.where(disparity_image > error_bound)
values = disparity_image[locations]
        
plt.xlim(0, x)
plt.ylim(y, 0)
plt.scatter(locations[1], locations[0], values, vmin = error_bound, vmax = 256)      
plt.colorbar()
plt.show()

But the colorbar is not scaled correctly, it doesn't look like the plot uses color as a scale either.

enter image description here

Upvotes: 0

Views: 50

Answers (1)

blunova
blunova

Reputation: 2532

Modify the code as follows:

colormap = plt.cm.get_cmap('plasma')
sp = plt.scatter(locations[1], locations[0], values, vmin=error_bound, vmax=256, cmap=colormap)
plt.colorbar(sp)

Choose the color scheme you like the most, take a look here.

Upvotes: 1

Related Questions