Closed as not planned
Closed as not planned
Description
Bug report
Bug description:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.datasets import load_diabetes
data = load_diabetes()
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = data.target
df = df.drop_duplicates()
df = df.ffill()
df.hist(bins=30, grid=False)
plt.suptitle('Histograms of Numerical Features')
plt.show()
sns.pairplot(df[['target', 'age', 'bmi', 's4', 's5']])
plt.suptitle('Pair Plot of Target and Selected Features', y=1.02)
plt.show()
corr_matrix = df.corr()
sns.heatmap(corr_matrix, annot=True, cmap='coolwarm', fmt='.2f')
plt.title('Heatmap of Correlation Matrix')
plt.show()
sns.boxplot(data=df.select_dtypes(include=[np.number]))
plt.title('Boxplots for Numerical Features')
plt.xticks(rotation=90)
plt.show()
plt.scatter(df['bmi'], df['age'], c=df['target'], cmap='viridis', alpha=0.6)
plt.colorbar(label='Diabetes Progression')
plt.xlabel('BMI')
plt.ylabel('Age')
plt.title('Scatter Plot of BMI vs Age Color-Coded by Target')
plt.show()
#################
The above code is randomly giving the following error:
Traceback (most recent call last):
File "D:/python work/p10.py", line 20, in <module>
sns.pairplot(df[['target', 'age', 'bmi', 's4', 's5']])
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\seaborn\axisgrid.py", line 2119, in pairplot
grid = PairGrid(data, vars=vars, x_vars=x_vars, y_vars=y_vars, hue=hue,
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\seaborn\axisgrid.py", line 1280, in __init__
fig = plt.figure(figsize=figsize)
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\matplotlib\pyplot.py", line 1022, in figure
manager = new_figure_manager(
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\matplotlib\pyplot.py", line 545, in new_figure_manager
return _get_backend_mod().new_figure_manager(*args, **kwargs)
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\matplotlib\backend_bases.py", line 3521, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\matplotlib\backend_bases.py", line 3526, in new_figure_manager_given_figure
return cls.FigureCanvas.new_manager(figure, num)
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\matplotlib\backend_bases.py", line 1811, in new_manager
return cls.manager_class.create_with_canvas(cls, figure, num)
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\matplotlib\backends\_backend_tk.py", line 479, in create_with_canvas
with _restore_foreground_window_at_end():
File "C:\Users\admin\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
File "C:\Users\admin\AppData\Roaming\Python\Python312\site-packages\matplotlib\backends\_backend_tk.py", line 43, in _restore_foreground_window_at_end
foreground = _c_internal_utils.Win32_GetForegroundWindow()
ValueError: PyCapsule_New called with null pointer
Sometime it executes successfully and sometimes it doesn't. If there is no bug then please provide me solution for this.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Metadata
Metadata
Assignees
Labels
No labels