Hello, I have a question because the Python assignment is difficult.
As shown in the screenshot above, each of the four files contains a Pushoverput folder from 00 to 20. Inside this folder are the out files of Node2 and Node4. At this time, the task is to make a code on the Python using the data in column 2 of Node 2 and column 6 of Node 4, draw a graph, and save it in the Figures folder.
In this process, I would like to know a code that can store a total of 22 graphs in the Figures folder, including 00 to 20 graphs using the for statement and a graph with 21 graphs drawn at the same time.
import pandas as pd
import matplotlib.pyplot as plt
csv_test=pd.read_csv(r'C:\Users\Jeong Min\Desktop\Term\0.5H\0.5_00.csv')
print(csv_test)
I separately extracted data from 00 of 0.5H folders and made a csv file, and I know how to load this file, but I don't know what's next.
python
Hmm. I'll write a very simple example code as an answer.
import pandas as pd
import matplotlib.pyplot as plt
root_dir = "PushoverOutput/"
node2 = pd.read_csv(root_dir + "Node2_Dsp.out", header=None)
node4 = pd.read_csv(root_dir + "Node4_Reaction.out", header=None)
df = pd.DataFrame({"Curvature":node2.iloc[:,1], "Moment":node4.iloc[:,5]})
print(df.to_markdown())
df.plot.line(x="Curvature", y="Moment", grid=True)
plt.savefig("Figures/result.jpg")
ROOT - PushoverOutput - Node2_Dsp.out
Node4_Reaction.out
- - Figures - result.jpg
- - script.py
To access a few columns in the Pandas DataFrame, use iloc
. Create a data frame by combining two data frames, node2 and node4, into the second (one for index) and sixth (five for index). Then, in a two-column data frame, you draw a graph as a plot function of Pandas.
And then finally, we store that graph as a function of plt.savefig
. It might be a little confusing here, but it's plt.savefig because the panda plot function uses matplotlib internally to render.
If you want to adjust the details of the graph, you can study matplotlib a little more.
© 2024 OneMinuteCode. All rights reserved.