PYTHON - Matplotlib: plot different datasets in a graph with colormap + axis and label width

103 Views Asked by At

I am trying to create a short script to plot some data from different Excel files. As these are overlapping on the same graph, I would like to use a color map to differentiate between each plot. I have tried different approaches but I do not understand how to get what I need, as it returns the plots using only the first color.

I have been trying to change axes and labels weight as well without using subplots() as this would return a plot after every for cycle.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import glob
import os
from os import path
import sys
import openpyxl

xlsx_files=glob.glob(r'C:\Users\path\**\*.xlsx'
)
xlsx_files.sort()

print(xlsx_files)
print(type(xlsx_files))
df_frames=[]
print('Number of plots: ', len(xlsx_files))
n=len(xlsx_files)
m=n

for file in xlsx_files:
    print('Plot: ', m)
    m=m-1
    df_frames.append(pd.read_excel(file))
    all_frames=pd.concat(df_frames)
    print(df_frames)
    ph_loops=all_frames[all_frames['Read (V)']==-0.5]
    x = ph_loops['Write (V)']
    y = ph_loops['ph0 (o)']
    colors=plt.cm.winter(np.linspace(0, 1, n))
    for i in range (n):
        plt.plot(x, y, c=colors[i], marker='.', linewidth=0.5, markersize=2)
        plt.tick_params(axis='y', colors='xkcd:orange')
        plt.xlabel('Write (V)', fontsize=12, weight='bold')
        plt.ylabel('Phase (deg)', color='xkcd:orange', fontsize=12, weight='bold')
        plt.title(file+'\n')
        plt.tick_params(width=2)
        plt.rcParams['axes.linewidth']=2
    plt.plot()
plt.show()

Graph of multiple plots with incorrect coloring

0

There are 0 best solutions below