I have a text file containing data points that I want to plot. The data is formatted a…
- User
I have a text file containing data points that I want to plot. The data is formatted a pair of x and y values separated by a space with each coordinate pair on its own line. Please write a Python script that accepts file names as a command line arguments and plots the data from each file on the same graph.
- Assistant
Here is a Python script that accepts file names as command line arguments and plots the data from each file on the same graph, with a pair of x and y values separated by a space on each line:
pythonimport matplotlib.pyplot as plt import sys def plot_data(filename): """Plots the data from the given text file on a graph.""" x = [] y = [] with open(filename, "r") as f: for line in f: x_value, y_value = line.split() x.append(float(x_value)) y.append(float(y_value)) plt.plot(x, y, label=filename) if __name__ == "__main__": """Plots the data from all of the given text files on the same graph.""" for filename in sys.argv[1:]: plot_data(filename) plt.xlabel("X") plt.ylabel("Y") plt.legend() plt.show()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →
- Human-written demonstration (OpenAssistant volunteers)Compare side by side →