Created
February 22, 2019 08:27
-
-
Save Bktero/92de1c44e7c94fc01e905e6cc654eeff to your computer and use it in GitHub Desktop.
[Python] Use Numpy and Matplotlib to save data to a file and load these data to plot them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
import matplotlib.pyplot as plt | |
import numpy as np | |
FILENAME = 'data.txt' | |
SEPARATOR = '\n' | |
# Data can be generated with any tool as long as the format is good | |
# Create one to show the format of the file | |
if not os.path.isfile(FILENAME): | |
generated = np.random.random_sample(100) | |
generated.tofile(FILENAME, sep=SEPARATOR) | |
# Load the file as a numpy array | |
loaded = np.fromfile(FILENAME, sep=SEPARATOR) | |
# Plot this array | |
plt.plot(loaded) | |
print(loaded) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment