How To Plot 10 Traces In Same Figure With Different Color In Python?
I need to plot 10 traces with different color in python, every trace is in a different file with the same extension .numpy., I mean by that that I have 10 files: trace1 trace2 tra
Solution 1:
No, you don't have to put everything in the same file. You can simply loop over a list of files and plot into the same axes
. For the color, it is the easiest if you simply grab a color for a colormap
. Here is a little example:
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
# Read in list of files. You might want to look into os.listdir()
traces=[list of filepaths to your .npy files]
# Create figure
fig=plt.figure()
fig.show()
ax=fig.add_subplot(111)
# Grab colormap
cmap = matplotlib.cm.get_cmap('jet')
# Loop through traces and plot them
for j,trace in enumerate(traces):
# Load file
dataArray= np.load(trace)
# Grab color
c=cmap(float(j)/len(traces))
# Plot
ax.plot(dataArray.T,color=c)
plt.show()
Post a Comment for "How To Plot 10 Traces In Same Figure With Different Color In Python?"