Simple (x,y) graph

Joined
Jan 30, 2023
Messages
6
Reaction score
0
Hi, I want to set up a simple graph with arbitrary x,y points, and then manually assign lines between those points. The problem with Matplotlib is that it tries to PLOT points. I want to just list a bunch of abitrary points with an x and a y value and manually draw lines between them. What program should I import to draw such a figure?
 
Joined
Jan 8, 2023
Messages
27
Reaction score
2
To achieve this, you can still rely on Matplotlib. You can apply the scatter function to display the arbitrary points and the plot function to manually connect them with lines. Here’s an example:
Python:
import matplotlib.pyplot as plt

# Define arbitrary points
points = [(1, 2), (3, 4), (5, 6), (7, 8)]

# Display points
x, y = zip(*points)
plt.scatter(x, y)

# Manually connect points with lines
plt.plot([1, 3], [2, 4])
plt.plot([5, 7], [6, 8])

plt.show()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top