!Feliz año¡, estoy aprendiendo python y generando gráficos usando matplotlib, no se que esta mal, espero alguien me pueda ayudar?
Tabla
date |
Type |
Result |
Code |
ID |
2/10/2020 |
A |
0.5 |
resxcsrfa01 |
805492 |
2/10/2020 |
A |
1 |
resxcsrfa02 |
805470 |
2/10/2020 |
B |
0.007 |
resxcsrfa03 |
805470 |
2/10/2020 |
D |
0.0124 |
resxcsrfa04 |
805492 |
2/10/2020 |
C |
0.013 |
resxcsrfa05 |
805470 |
2/10/2020 |
D |
0.0038 |
resxcsrfa06 |
805470 |
2/10/2020 |
C |
0.016 |
resxcsrfa07 |
805492 |
2/10/2020 |
B |
0.0025 |
resxcsrfa08 |
805492 |
3/10/2020 |
C |
0.017 |
resxcsrfa09 |
807291 |
3/10/2020 |
A |
0.5 |
resxcsrfa10 |
807291 |
3/10/2020 |
B |
0.012 |
resxcsrfa11 |
807291 |
3/10/2020 |
D |
0.0166 |
resxcsrfa12 |
807291 |
4/10/2020 |
D |
0.0116 |
resxcsrfa13 |
809217 |
4/10/2020 |
C |
0.014 |
resxcsrfa14 |
809217 |
4/10/2020 |
B |
0.009 |
resxcsrfa15 |
809217 |
Codigo
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
figsize = (16,8)
def generate_lineplots(df, ax, field):
"""Generate line plots comparing field for white drivers with minority drivers"""
df1 = df.loc(:,('date','Type', 'ID', 'Result'))
df1 = df1.pivot(index=("date", 'ID'), columns=('Type'), values= field).reset_index()
ax = df1.plot(ax=ax, x='date', y=field, marker='o', label=field)
return ax
def format_lineplot(ax, field):
"""Format and label to line plots chart"""
ax.set_xlabel('{}'.format('date'))
ax.set_ylabel('{}'.format(field))
ax.set_title("{}".format(field))
lim = max(ax.get_xlim()(1), ax.get_ylim()(1))
ax.set_xlim(0, lim)
ax.set_ylim(0, lim)
#diag_line, = ax.plot(ax.get_xlim(), ax.get_ylim(), ls="--", c=".3")
ax.legend()
return ax
def generate_comparison_lineplot(df):
"""Generate line plots"""
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=figsize)
#generate_lineplots(df, axes(0,0), 'A')
format_lineplot(axes(0,0), 'A')
#generate_lineplots(df, axes(1,0), 'B')
format_lineplot(axes(1,0), 'B')
#generate_lineplots(df, axes(0,1), 'C')
format_lineplot(axes(0,1), 'C')
#generate_lineplots(df, axes(1,1), 'D')
format_lineplot(axes(1,1), 'D')
return fig
al correr no me sale
generate_comparison_lineplot(xx)

y quisiera obtener algo así?
