diff --git a/relecov_core/utils/plotly_dash_graphics.py b/relecov_core/utils/plotly_dash_graphics.py index ca7e564..38ff693 100644 --- a/relecov_core/utils/plotly_dash_graphics.py +++ b/relecov_core/utils/plotly_dash_graphics.py @@ -2,7 +2,7 @@ from django_plotly_dash import DjangoDash from dash.dependencies import Input, Output from dash import dcc, html -from plotly.express import bar +import plotly.express as px from dash.exceptions import PreventUpdate @@ -12,7 +12,7 @@ def dash_bar_lab(option_list, data): option.append({"label": opt_list, "value": opt_list}) app = DjangoDash("samplePerLabGraphic") - empty_fig = bar(x=[0], y=[0], height=300) + empty_fig = px.bar(x=[0], y=[0], height=300) app.layout = html.Div( [ @@ -45,7 +45,7 @@ def update_graph(select_lab_name): if select_lab_name == 1: raise PreventUpdate sub_data = data[data.lab_name == select_lab_name] - graph = bar( + graph = px.bar( sub_data, x=sub_data["date"], y=sub_data["num_samples"], diff --git a/relecov_core/utils/plotly_graphics.py b/relecov_core/utils/plotly_graphics.py index 3c24845..aa58cba 100644 --- a/relecov_core/utils/plotly_graphics.py +++ b/relecov_core/utils/plotly_graphics.py @@ -1,8 +1,8 @@ # Generic imports from plotly.offline import plot -from plotly.graph_objects import Figure, Bar, Scatter, Indicator, Pie -from plotly.express import bar -from plotly.figure_factory import create_bullet +import plotly.graph_objects as go +import plotly.express as px +import plotly.figure_factory as ff from dash_bio import NeedlePlot from dash import dcc, html from django_plotly_dash import DjangoDash @@ -15,10 +15,10 @@ def bar_graphic(data, col_names, legend, yaxis, options): colors = options["colors"] else: colors = ["#0099ff", "#1aff8c", "#ffad33", "#ff7733", "#66b3ff", "#66ffcc"] - fig = Figure() + fig = go.Figure() for idx in range(1, len(col_names)): fig.add_trace( - Bar( + go.Bar( x=data[col_names[0]], y=data[col_names[idx]], name=legend[idx - 1], @@ -53,8 +53,8 @@ def bar_graphic(data, col_names, legend, yaxis, options): def line_graphic(x_data, y_data, options): # Create line - fig = Figure() - fig.add_trace(Scatter(x=x_data, y=y_data, mode="lines", name="lines")) + fig = go.Figure() + fig.add_trace(go.Scatter(x=x_data, y=y_data, mode="lines", name="lines")) fig.update_layout( height=options["height"], @@ -73,7 +73,7 @@ def line_graphic(x_data, y_data, options): def histogram_graphic(data, col_names, options): - graph = bar( + graph = px.bar( data, y=col_names[1], x=col_names[0], text_auto=True, width=options["width"] ) # Customize aspect @@ -96,8 +96,8 @@ def histogram_graphic(data, col_names, options): def gauge_graphic(data): - graph = Figure( - Indicator( + graph = go.Figure( + go.Indicator( mode="gauge+number", value=data["value"], number={"suffix": "%"}, @@ -125,7 +125,7 @@ def bullet_graphic(value, title): ] measure_colors = ["rgb(68, 107, 162)", "rgb(0, 153, 0)"] - fig = create_bullet( + fig = ff.create_bullet( data, titles="label", title=title, @@ -157,8 +157,8 @@ def pie_graphic(data, names, title, show_legend=False): "darkorange", "turquoise", ] - fig = Figure( - data=Pie( + fig = go.Figure( + data=go.Pie( labels=names, values=data, ) diff --git a/relecov_core/utils/samples.py b/relecov_core/utils/samples.py index ab19575..c510b9f 100644 --- a/relecov_core/utils/samples.py +++ b/relecov_core/utils/samples.py @@ -4,7 +4,7 @@ import shutil from collections import OrderedDict from datetime import datetime -from pandas import DataFrame as PandasDataFrame +import pandas as pd from django.contrib.auth.models import Group, User from django.core.files.storage import FileSystemStorage from django.conf import settings @@ -292,7 +292,7 @@ def create_date_sample_bar(lab_sample, cust_data): """Create bar graph where X-axis are the dates and Y-axis the number of samples """ - df = PandasDataFrame(lab_sample.items(), columns=cust_data["col_names"]) + df = pd.DataFrame(lab_sample.items(), columns=cust_data["col_names"]) histogram = relecov_core.utils.plotly_graphics.histogram_graphic( df, cust_data["col_names"], cust_data["options"] ) @@ -303,7 +303,7 @@ def create_dash_bar_for_each_lab(): """Function collect the list of lab and the samples per date per each lab and call dash plotly function to display """ - df_data = PandasDataFrame(get_sample_per_date_per_all_lab(detailed=True)) + df_data = pd.DataFrame(get_sample_per_date_per_all_lab(detailed=True)) relecov_core.utils.plotly_dash_graphics(get_all_lab_list(), df_data) return diff --git a/relecov_core/utils/samples_map.py b/relecov_core/utils/samples_map.py index 7efa350..013b561 100644 --- a/relecov_core/utils/samples_map.py +++ b/relecov_core/utils/samples_map.py @@ -2,7 +2,7 @@ import os import json import pandas as pd -from plotly.express import choropleth_mapbox +import plotly.express as px from dash import dcc, html from django_plotly_dash import DjangoDash @@ -37,7 +37,7 @@ def create_samples_received_map(): data["samples"].append("0") ldata = pd.DataFrame(data) - fig = choropleth_mapbox( + fig = px.choropleth_mapbox( ldata, geojson=counties, locations=ldata.ccaa_id,