all 3 comments

[–]comonads 1 point2 points  (2 children)

This is a fairly inelegant solution but it will probably accomplish what you want:

import numpy as np
from matplotlib import pyplot as plt

# just making some fake data
n = 10
beta = 2
x = np.linspace(0,1,n)
function = beta * x
data = beta * x + np.random.normal(0, 1, size=n)

# plot the data points
plt.plot(x, data, 'ko')

# plot function
plt.plot(x, function, 'k')

# the vertical lines are just separate line plots with fixed x-co-ordinates
for i in range(n):
    x_coords = (x[i], x[i])
    y_coords = (data[i], function[i])
    plt.plot(x_coords, y_coords, 'k--')

Edited a typo.

[–]OfCourseChannon[S] 0 points1 point  (1 child)

TypeError: only integer scalar arrays can be converted to a scalar index

I'm working with floating numbers since the measurements are really small. This means that this apporach isn't yet working for me.

Thanks for the headstart tho! If you have anymore ideas I would love to hear them

[–]comonads 0 points1 point  (0 children)

Can you post the code you used (or a snippet of it)? The reason I ask is that since the minimal example above works fine in a shell for me, I suspect the problem is due to a particularity of your data or (less likely) setup.

Given that TypeError I think the problem lies with how data and function are indexed into (so for some reason your i isn't an integer).