darts
darts copied to clipboard
Gridlines automatically created in matplotlib and seaborn plots [BUG]
Darts package seems to have some parameter under the hood that inserts gridlines into every matplotlib and seaborn plot:
If i do not import darts, this seaborn heatmap doesnt show gridlines,
import seaborn as sns
import numpy as np
from lib.data_ingestion.general_utils import pickle_file, load_pickle_file
combined_park_df = load_pickle_file(f'pickle_files/balti2_preprocessed_df.pkl')
overall_corr = combined_park_df[['edm_power_feed_in', 'edm_p_mw', 'power_diff']].corr()
matrix = np.triu(overall_corr)
sns.heatmap(overall_corr, annot = True)
However, if I include darts import as part of the imports, gridlines will appear in the plot:
import seaborn as sns
import numpy as np
from lib.data_ingestion.general_utils import pickle_file, load_pickle_file
import darts
combined_park_df = load_pickle_file(f'pickle_files/balti2_preprocessed_df.pkl')
overall_corr = combined_park_df[['edm_power_feed_in', 'edm_p_mw', 'power_diff']].corr()
matrix = np.triu(overall_corr)
sns.heatmap(overall_corr, annot = True)
Is there a reason why it's implemented this way?
Hi @ETTAN93, when importing anything from Darts, we change the matplotlib settings/style for plotting.
You can deactivate this with environment variable "DARTS_CONFIGURE_MATPLOTLIB"] = "0"
.
Like below
import os
os.environ["DARTS_CONFIGURE_MATPLOTLIB"] = "0"
import darts
import matplotlib.pyplot as plt
import seaborn as sns
iris = sns.load_dataset('iris')
overall_corr = iris[iris.columns[:4]].corr()
sns.heatmap(overall_corr, annot=True)
plt.show()
There were already some discussion about not changing the style by default (see #924). Maybe we should apply this at some point.
@madtoinou what do you think about this?
I agree that not changing the global config would be better, especially if users use Darts in the context of large projects in combination with other plotting libraries.
Hi @madtoinou and @dennisbader, I'm not sure if this is a related issue but I think it is also related to plotting functions that are provided by Darts. For example, I have set os.environ["DARTS_CONFIGURE_MATPLOTLIB"] = "0"
according to the suggested solution but it didn't solve the issues below:
Example 1: plot_residuals_analysis
function
Example 2:
import lightgbm as lgb
lgb_model = lgbm_model.get_estimator(horizon=0, target_dim=0)
imp = lgb_model.booster_.feature_importance()
features_names = lgbm_model.lagged_feature_names
[lgbm_model.lagged_feature_names[idx] for idx in np.argsort(imp)[::-1]]
lgb.plot_importance(lgb_model, importance_type = 'split')
The formatting of the diagrams are all over the place.
@ETTAN93 you may provide a full reproducible example. I think some other library or code is messing with the matplot parameters in your case. At least i can not reproduce it. And if so, it may be better to open a separate issue.
import os
# Make sure to set this env variable BEFORE importing darts!
os.environ.setdefault("DARTS_CONFIGURE_MATPLOTLIB", "0")
import darts
from darts.utils.statistics import plot_residuals_analysis
import numpy as np
ts = darts.TimeSeries.from_values(np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]))
plot_residuals_analysis(ts)
I agree that not changing the global config would be better, especially if users use Darts in the context of large projects in combination with other plotting libraries.
@madtoinou @dennisbader I may can work on this, but would need some more information:
- Do you simply want to use the standard matplot settings as default?
- Maybe still provide a function to change the rcParams to
u8plots_mplstyle
(opt-in instead of opt-out as it is now). And also respect theDARTS_CONFIGURE_MATPLOTLIB
, but default is 0
- Maybe still provide a function to change the rcParams to
- Or do you not want to change the rcParams, but configure each individual plot so that it still looks like the
u8plots_mplstyle
?
I personally would prefer the first one (and only custom plots if its really necessary or helpful. Like e.g. adding a grid). Because it's much easier and less error prone
A third option would be, to at least mention DARTS_CONFIGURE_MATPLOTLIB
in the documentation. E.g. under the FAQ. I could do that too