mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-14 08:16:54 +08:00
Fix 'report' compatibility with matplotlib versions
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
import plotly.tools as tls
|
|
||||||
import plotly.graph_objs as go
|
import plotly.graph_objs as go
|
||||||
|
|
||||||
import statsmodels.api as sm
|
import statsmodels.api as sm
|
||||||
@@ -80,9 +79,37 @@ def _plot_qq(data: pd.Series = None, dist=stats.norm) -> go.Figure:
|
|||||||
:param dist:
|
:param dist:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
fig, ax = plt.subplots(figsize=(8, 5))
|
_plt_fig = sm.qqplot(data.dropna(), dist=dist, fit=True, line="45")
|
||||||
_mpl_fig = sm.qqplot(data.dropna(), dist, fit=True, line="45", ax=ax)
|
plt.close(_plt_fig)
|
||||||
return tls.mpl_to_plotly(_mpl_fig)
|
qqplot_data = _plt_fig.gca().lines
|
||||||
|
fig = go.Figure()
|
||||||
|
|
||||||
|
fig.add_trace({
|
||||||
|
'type': 'scatter',
|
||||||
|
'x': qqplot_data[0].get_xdata(),
|
||||||
|
# 'x': [0, 1],
|
||||||
|
'y': qqplot_data[0].get_ydata(),
|
||||||
|
# 'y': [1, 2],
|
||||||
|
'mode': 'markers',
|
||||||
|
'marker': {
|
||||||
|
'color': '#19d3f3'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
fig.add_trace({
|
||||||
|
'type': 'scatter',
|
||||||
|
'x': qqplot_data[1].get_xdata(),
|
||||||
|
# 'x': [0, 1],
|
||||||
|
'y': qqplot_data[1].get_ydata(),
|
||||||
|
# 'y': [1, 2],
|
||||||
|
'mode': 'lines',
|
||||||
|
'line': {
|
||||||
|
'color': '#636efa'
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
del qqplot_data
|
||||||
|
return fig
|
||||||
|
|
||||||
|
|
||||||
def _pred_ic(pred_label: pd.DataFrame = None, rank: bool = False, **kwargs) -> tuple:
|
def _pred_ic(pred_label: pd.DataFrame = None, rank: bool = False, **kwargs) -> tuple:
|
||||||
|
|||||||
Reference in New Issue
Block a user