You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
with open(r"C:\Users\lg\Desktop\trajectory\jeju060100-500.txt"),open(r"C:\Users\lg\Desktop\trajectory\jeju060200-500.txt"),open(r"C:\Users\lg\Desktop\trajectory\jeju060300-500.txt") as traj:
contents = traj.readlines()
color_dict = {1 : 'red',
2 : 'green',
3 : 'blue'}
for traj in trajgroup :
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = color_dict[day]
with open(r"C:\Users\lg\Desktop\trajectory\jeju060100-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'red'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060200-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'orange'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060300-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'yellow'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060400-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'green'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060500-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060600-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'black'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060700-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'purple'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060800-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
with open(r"C:\Users\lg\Desktop\trajectory\jeju060900-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
with open(r"C:\Users\lg\Desktop\trajectory\jeju061000-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
with open(r"C:\Users\lg\Desktop\trajectory\jeju061100-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
with open(r"C:\Users\lg\Desktop\trajectory\jeju061200-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
with open(r"C:\Users\lg\Desktop\trajectory\jeju061300-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
with open(r"C:\Users\lg\Desktop\trajectory\jeju061400-500.txt") as traj:
contents = traj.readlines()
last_timepoint = 9
data = contents[last_timepoint].split()
day = int(data[4])
traj.trajcolor = 'blue'
The trajectories loaded in the with open() statements have no connection to the Trajectory objects initiated in trajgroup, despite being derived from the same files. This is why in the second example none of the colors are applied. In the first example, you get all blue trajectories because the third file is opened, contents is created and persists, and trajectory color is assigned to all Trajectory objects in trajgroup based on these contents from that one trajectory.
What you need to do is inspect the Trajectory objects in your TrajectoryGroup and assign colors to them, NOT reopen and parse the original files. To make your second example work:
hi Mellissa!
I want to plot a different color graph for each day.
So I made two codes.
The first one is
_
And second one is
then Its results are shown in the following figures.
How can I make the right graph?
Best Regards
Chaelin.
The text was updated successfully, but these errors were encountered: