How do I make a scatter plot in python 3 using (number, value) coordinate

343 Views Asked by At

How would I make a scatter plot using (number, value) where number is on a number line; there are no negative values on either variable. pseudocode:

first_point = (1, secrets.randbit(4))
second_point = (2, secrets.randbit(4))
...
plot = create_plot((first_point, second_point, ...))
display_plot(plot)

This would help me out greatly as it would make graphing much easier to do as all that I could find is to make bar graphs and even then it is still relatively complex. If possible, could you simplify the code/function so much that all you have to input is the points as a tuple or list. Also making it so that the graph auto adjusts for the range of inputs. Explaining how and why the code works would be great so that I can create a scatter plot of the Collatz Conjecture. If there is an easy solution with pygame, I am all ears to it, but using the turtle library is fine. Thanks in advance.

1

There are 1 best solutions below

1
On BEST ANSWER

My own solution:

def create_graph(list):
    for item in list:
        x = item[0]
        y = item[1]
        pyplot.scatter(x, y)

first_point = (rand, rand)
second_point = (rand, rand)
...
create_graph((first_point, second_point, ...))
pyplot.show()

This is my solution to the problem and I think it is great. Thanks to Michael who told me about pyplot.scatter.