Python Forum
Matplotlib is all messed up! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: Matplotlib is all messed up! (/Thread-Matplotlib-is-all-messed-up)



Matplotlib is all messed up! - 64humans - Jan-21-2019

Hi! I created a convex hull algorithm in c and it outputs all the points and the convex hull into datapoints.txt and convexhull.txt.
However, when I use the code below matplotlib scrambles all the axis. Meaning that x-axis may be correct but the y one goes 5 20 10.

Is there any way to force matplotlib to simply draw a point on the coordinate that I read from a file?

main.py
import matplotlib.pyplot as plt

f = open("dataset.txt", "r")
data = f.read()
f.close()

data = data.split("\n")
data = data[:len(data)-1]
for datapoint in data:
    splitdata = list(datapoint.split(" "))
    plt.plot(splitdata[0], splitdata[1], "ro")

plt.show()
dataset.txt
10 10
15 5
16 10
16 20
30 10

Note: I remove the last element of data because Atom forces a newline on save...

Thanks! Smile


RE: Matplotlib is all messed up! - libervurto - Mar-16-2019

You made the same stupid mistake as me! Tongue
Why might the "numbers" on the y-axis not be in numerical order?... Think