import pandas
import ipywidgets as widgets
from ipywidgets import interact, interactive, fixed
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from plot_function import bar_scatter_plot
En siguiente lugar cargamos los datos, el fichero data.csv
ubicado en el directorio data
. Tras ello se previsualizan las primeras instancias.
datos = pandas.read_csv("data/datos.csv")
datos.head()
Por último, modifico los nombres de la columnas para evitar problemas con los espacios.
datos.columns = ['Worldcat_entity', 'Works', 'Publications', 'Library_Holdings', 'Google_Scholar_Citations']
datos.head()
En primer lugar hago una tabla interactiva con la que poder filtrar los datos de las distintas columnas.
@interact
def show_entities_more_than(column=['Works', 'Publications', 'Library_Holdings', 'Google_Scholar_Citations'], x=100):
return datos.loc[datos[column] > x]
Tras ello un gráfico de barras interactivo en el que aparecen dos series de datos. En este caso el mismo pero de dos formas diferentes.
# pandas
def plot_entities_more_than(Serie1=['Works', 'Publications', 'Library_Holdings', 'Google_Scholar_Citations'],
Serie2=['Publications', 'Works', 'Library_Holdings', 'Google_Scholar_Citations']):
grafico_barras = datos.plot.bar(x='Worldcat_entity', y=[Serie1, Serie2],
figsize=(20,10),
rot=45)
grafico_barras = grafico_barras.set_xticklabels(datos.Worldcat_entity,
fontdict={'horizontalalignment': 'right', 'size':12})
return grafico_barras
w=interactive(plot_entities_more_than)
w
# matplotlib
def plot_entities_more_than(Serie1=['Works', 'Publications', 'Library_Holdings', 'Google_Scholar_Citations'],
Serie2=['Publications', 'Works', 'Library_Holdings', 'Google_Scholar_Citations']):
labels = datos['Worldcat_entity']
x = np.arange(len(labels))
width = 0.25
fig, ax = plt.subplots(figsize=(20,10), dpi= 100)
rects1 = ax.bar(x - width/2, datos[Serie1], width, label=Serie1)
rects2 = ax.bar(x + width/2, datos[Serie2], width, label=Serie2)
ax.set_xticks(x)
ax.set_xlabel('Worldcat_entity', fontdict={'size':14})
ax.set_xticklabels(labels, rotation=45, fontdict={'horizontalalignment': 'right', 'size':12})
ax.legend()
fig.tight_layout()
return plt.show()
w=interactive(plot_entities_more_than)
w
Por último, ejecuto la función que he preparado para hacer el ranking de autores por library holdings.
bar_scatter_plot(datos)