CoolFace
Apppublic

Cuarto/Matplotlib

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py83 linesDownload Raw Back to root
1import gradio as gr2import plotly.graph_objects as go3import pandas as pd4 5# Datos para la línea cronológica6data = pd.DataFrame([7    {"start_year": 1959, "end_year": 1960, "enfoque": "ENFOQUE PSICOANALÍTICO"},8    {"start_year": 1960, "end_year": 1970, "enfoque": "TEORÍAS SOCIOLÓGICAS Y ECOLÓGICAS"},9    {"start_year": 1970, "end_year": 1980, "enfoque": "PRIMERAS APROXIMACIONES CRIMINOLÓGICAS"},10    {"start_year": 1970, "end_year": 1980, "enfoque": "TEORÍAS FEMINISTAS Y SOCIOCULTURALES"},11    {"start_year": 1980, "end_year": 2000, "enfoque": "TEORÍAS CRIMINOLÓGICAS"},12    {"start_year": 2000, "end_year": 2024, "enfoque": "ENFOQUES MULTIDISCIPLINARES"}13])14 15# Colores para cada enfoque16colors = {17    "ENFOQUE PSICOANALÍTICO": "#FF9999",18    "TEORÍAS SOCIOLÓGICAS Y ECOLÓGICAS": "#66B2FF",19    "PRIMERAS APROXIMACIONES CRIMINOLÓGICAS": "#99FF99",20    "TEORÍAS FEMINISTAS Y SOCIOCULTURALES": "#FFCC99",21    "TEORÍAS CRIMINOLÓGICAS": "#FF6666",22    "ENFOQUES MULTIDISCIPLINARES": "#CCCCFF"23}24 25# Función para crear la línea cronológica26def create_plot():27    fig = go.Figure()28 29    # Añadir los tramos de colores30    for _, row in data.iterrows():31        fig.add_trace(go.Scatter(32            x=[row['start_year'], row['end_year']],33            y=[0.5, 0.5],34            mode='lines',35            line=dict(color=colors[row['enfoque']], width=15),36            name=row['enfoque']37        ))38 39    # Añadir etiquetas de los enfoques40    for _, row in data.iterrows():41        fig.add_annotation(42            x=(row['start_year'] + row['end_year']) / 2,43            y=0.55,44            text=row['enfoque'],45            showarrow=False,46            font=dict(size=10, color='black', family='Arial'),47            align='center'48        )49 50    # Configurar los ejes51    fig.update_xaxes(52        title_text='Año',53        tickvals=list(range(1959, 2025, 5)),54        ticktext=list(range(1959, 2025, 5)),55        title_font=dict(size=14),56        tickangle=4557    )58    fig.update_yaxes(visible=False)59 60    # Añadir título y diseño61    fig.update_layout(62        title="Línea Cronológica de Investigaciones sobre Agresiones Sexuales Grupales (ASG)",63        title_font=dict(size=14),64        plot_bgcolor='#f7f7f7',65        xaxis_title='Año',66        showlegend=True,67        legend=dict(x=1, y=1, traceorder='normal')68    )69 70    return fig.to_html(full_html=False)71 72# Crear la interfaz de usuario con Gradio73iface = gr.Interface(74    fn=create_plot,75    inputs=[],76    outputs=gr.HTML(label="Línea Cronológica"),77    live=True78)79 80# Ejecutar la interfaz81if __name__ == "__main__":82    iface.launch()83