Issue
As the title states I have some random X and Y data points:
+-----+-----+
| P1X | P1Y |
+-----+-----+
| 1 | 2 |
| 2 | 3 |
| -1 | 4 |
+-----+-----+
d = {'P1X': [1,2,-1], 'P1Y': [2,3,4]}
df_data = pd.DataFrame(data=d)
and then I graph them using a scatterplot like so:
import seaborn as sns
from matplotlib import pyplot as plt
ax = sns.scatterplot(data=df_data, x='P1X', y='P1Y', legend=False)
plt.show()
Now how would I draw a black line horizontally and vertically at each point? Any and all answers are apprecatied!
Solution
You could simply loop over the x and y values, and call axvline and axyline from plt.
import matplotlib.pyplot as plt
x_data = [-1, 2, 3]
y_data = [2, 3, 5]
plt.scatter(x_data, y_data, c='red')
for x, y in zip(x_data, y_data):
plt.axvline(x=x, color='b', linestyle='-')
plt.axhline(y=y, color='g', linestyle='-')
Answered By - Sandertjuhh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.