matplotlib-show for loop

https://stackoverflow.com/questions/11874767/real-time-plotting-in-while-loop-with-matplotlib
## 题目重述 实验数据位于文件 `regress_data1.xlsx` 中,要求完成以下任务: 1. 绘制数据散点图,其中横轴为“人口”,纵轴为“收益”; 2. 构建线性回归模型 $ y = ax + b $,使用最小二乘法求解参数 $ a $ 和 $ b $,采用两种方法: - 使用 NumPy 内置函数; - 使用 Python 循环手动实现; 3. 构建相同模型,以最小平方误差为损失函数,使用梯度下降算法求解参数: - 批量梯度下降(Batch GD); - 随机梯度下降(Stochastic GD); - 小批量梯度下降(Mini-batch GD); 4. 使用 `sklearn` 建立回归模型,并评估其性能(如 $ R^2 $、MSE 等)。 --- ## 给出答案(带注释的完整 Python 代码) ```python import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression from sklearn.metrics import mean_squared_error, r2_score import warnings # 忽略字体警告和收敛警告 warnings.filterwarnings("ignore") plt.rcParams['axes.unicode_minus'] = False # 正常显示负号 # ----------------------------- # 1. 加载数据 # ----------------------------- # 读取 Excel 文件中的数据 data = pd.read_excel('regress_data1.xlsx') # 提取“人口”和“收益”列 x = data['人口'].values # 形状: (n,) y = data['收益'].values # 形状: (n,) n = len(x) # ----------------------------- # 2. 绘制散点图 # ----------------------------- plt.figure(figsize=(10, 6)) plt.scatter(x, y, color='blue', alpha=0.7, label='数据点') plt.xlabel('人口') plt.ylabel('收益') plt.title('人口 vs 收益 散点图') plt.grid(True, linestyle='--', alpha=0.5) plt.legend() plt.show() # ----------------------------- # 3. 最小二乘法求解 y = ax + b # ----------------------------- # 方法一:使用 NumPy 的 polyfit 函数 a_numpy, b_numpy = np.polyfit(x, y, 1) # 方法二:使用循环手动实现最小二乘法 x_mean = np.mean(x) y_mean = np.mean(y) numerator = 0.0 denominator = 0.0 for i in range(n): numerator += (x[i] - x_mean) * (y[i] - y_mean) denominator += (x[i] - x_mean) ** 2 a_loop = numerator / denominator b_loop = y_mean - a_loop * x_mean print("【最小二乘法结果】") print(f"NumPy 函数法: a = {a_numpy:.4f}, b = {b_numpy:.4f}") print(f"循环实现法: a = {a_loop:.4f}, b = {b_loop:.4f}") # ----------------------------- # 4. 梯度下降算法 # ----------------------------- def add_intercept(X): """添加截距项(x0=1)""" return np.column_stack([np.ones(len(X)), X]) X = add_intercept(x) # (n, 2): 第一列为1,第二列为x y = y.reshape(-1, 1) # (n, 1) # 参数初始化 np.random.seed(42) theta = np.random.randn(2, 1) * 0.1 learning_rate = 0.0001 epochs = 10000 # 批量梯度下降 (BGD) theta_bgd = theta.copy() for _ in range(epochs): gradient = (1/n) * X.T @ (X @ theta_bgd - y) theta_bgd -= learning_rate * gradient a_bgd, b_bgd = theta_bgd[1, 0], theta_bgd[0, 0] # 随机梯度下降 (SGD) theta_sgd = theta.copy() for epoch in range(epochs): for i in range(n): xi = np.array([[1, x[i]]]) # (1, 2) yi = y[i] # (1, 1) gradient = xi.T @ (xi @ theta_sgd - yi) theta_sgd -= learning_rate * gradient a_sgd, b_sgd = theta_sgd[1, 0], theta_sgd[0, 0] # 小批量梯度下降 (MBGD),batch_size=16 theta_mbgd = theta.copy() batch_size = 16 for epoch in range(epochs): indices = np.random.permutation(n) X_shuffled = X[indices] y_shuffled = y[indices] for start in range(0, n, batch_size): end = start + batch_size X_batch = X_shuffled[start:end] y_batch = y_shuffled[start:end] m = len(X_batch) gradient = (1/m) * X_batch.T @ (X_batch @ theta_mbgd - y_batch) theta_mbgd -= learning_rate * gradient a_mbgd, b_mbgd = theta_mbgd[1, 0], theta_mbgd[0, 0] print("\n【梯度下降结果】") print(f"批量梯度下降: a = {a_bgd:.4f}, b = {b_bgd:.4f}") print(f"随机梯度下降: a = {a_sgd:.4f}, b = {b_sgd:.4f}") print(f"小批量梯度下降: a = {a_mbgd:.4f}, b = {b_mbgd:.4f}") # ----------------------------- # 5. 使用 sklearn 建模与评估 # ----------------------------- model_sk = LinearRegression() model_sk.fit(x.reshape(-1, 1), y.ravel()) y_pred_sk = model_sk.predict(x.reshape(-1, 1)) mse = mean_squared_error(y, y_pred_sk) r2 = r2_score(y, y_pred_sk) print("\n【sklearn 模型结果】") print(f"斜率 a = {model_sk.coef_[0]:.4f}, 截距 b = {model_sk.intercept_:.4f}") print(f"均方误差 MSE = {mse:.4f}") print(f"决定系数 R² = {r2:.4f}") # ----------------------------- # 6. 绘制所有回归线对比图 # ----------------------------- plt.figure(figsize=(12, 7)) plt.scatter(x, y, color='blue', alpha=0.6, label='原始数据') x_plot = np.linspace(x.min(), x.max(), 100) plt.plot(x_plot, a_numpy * x_plot + b_numpy, color='green', label='最小二乘法(NumPy)', linewidth=2) plt.plot(x_plot, a_bgd * x_plot + b_bgd, color='orange', linestyle='-.', label='批量梯度下降', linewidth=2) plt.plot(x_plot, model_sk.coef_[0] * x_plot + model_sk.intercept_, color='red', label='Sklearn 模型', linewidth=2) plt.xlabel('人口') plt.ylabel('收益') plt.title('不同方法拟合的线性回归模型对比') plt.legend() plt.grid(True, alpha=0.5) plt.tight_layout() plt.show() 修缮代码使可视化图片的文字可以显示成功
10-27
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "D:\python\Anaconda3\envs\d2l\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\python\Anaconda3\envs\d2l\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel_launcher.py", line 18, in <module> app.launch_new_instance() File "D:\python\Anaconda3\envs\d2l\lib\site-packages\traitlets\config\application.py", line 1075, in launch_instance app.start() File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\kernelapp.py", line 739, in start self.io_loop.start() File "D:\python\Anaconda3\envs\d2l\lib\site-packages\tornado\platform\asyncio.py", line 211, in start self.asyncio_loop.run_forever() File "D:\python\Anaconda3\envs\d2l\lib\asyncio\base_events.py", line 601, in run_forever self._run_once() File "D:\python\Anaconda3\envs\d2l\lib\asyncio\base_events.py", line 1905, in _run_once handle._run() File "D:\python\Anaconda3\envs\d2l\lib\asyncio\events.py", line 80, in _run self._context.run(self._callback, *self._args) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\kernelbase.py", line 519, in dispatch_queue await self.process_one() File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\kernelbase.py", line 508, in process_one await dispatch(*args) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\kernelbase.py", line 400, in dispatch_shell await result File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\ipkernel.py", line 368, in execute_request await super().execute_request(stream, ident, parent) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\kernelbase.py", line 767, in execute_request reply_content = await reply_content File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\ipkernel.py", line 455, in do_execute res = shell.run_cell( File "D:\python\Anaconda3\envs\d2l\lib\site-packages\ipykernel\zmqshell.py", line 602, in run_cell return super().run_cell(*args, **kwargs) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py", line 3048, in run_cell result = self._run_cell( File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py", line 3103, in _run_cell result = runner(coro) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\async_helpers.py", line 129, in _pseudo_sync_runner coro.send(None) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py", line 3308, in run_cell_async has_raised = await self.run_ast_nodes(code_ast.body, cell_name, File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py", line 3490, in run_ast_nodes if await self.run_code(code, result, async_=asy): File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py", line 3550, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "d:\Temp\ipykernel_10160\1106343824.py", line 1, in <module> get_ipython().run_line_magic('matplotlib', 'inline') File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py", line 2456, in run_line_magic result = fn(*args, **kwargs) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui) File "D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py", line 3630, in enable_matplotlib from matplotlib_inline.backend_inline import configure_inline_support File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib_inline\__init__.py", line 1, in <module> from . import backend_inline, config # noqa File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib_inline\backend_inline.py", line 6, in <module> import matplotlib File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\__init__.py", line 161, in <module> from . import _api, _version, cbook, _docstring, rcsetup File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module> from matplotlib.colors import Colormap, is_color_like File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\colors.py", line 56, in <module> from matplotlib import _api, _cm, cbook, scale File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\scale.py", line 22, in <module> from matplotlib.ticker import ( File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\ticker.py", line 138, in <module> from matplotlib import transforms as mtransforms File "D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\transforms.py", line 49, in <module> from matplotlib._path import ( --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) AttributeError: _ARRAY_API not found --------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[1], line 1 ----> 1 get_ipython().run_line_magic('matplotlib', 'inline') 2 import os 3 import pandas as pd File D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py:2456, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth) 2454 kwargs['local_ns'] = self.get_local_scope(stack_depth) 2455 with self.builtin_trap: -> 2456 result = fn(*args, **kwargs) 2458 # The code below prevents the output from being displayed 2459 # when using magics with decorator @output_can_be_silenced 2460 # when the last Python token in the expression is a ';'. 2461 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False): File D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\magics\pylab.py:99, in PylabMagics.matplotlib(self, line) 97 print("Available matplotlib backends: %s" % backends_list) 98 else: ---> 99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui) 100 self._show_matplotlib_backend(args.gui, backend) File D:\python\Anaconda3\envs\d2l\lib\site-packages\IPython\core\interactiveshell.py:3630, in InteractiveShell.enable_matplotlib(self, gui) 3609 def enable_matplotlib(self, gui=None): 3610 """Enable interactive matplotlib and inline figure support. 3611 3612 This takes the following steps: (...) 3628 display figures inline. 3629 """ -> 3630 from matplotlib_inline.backend_inline import configure_inline_support 3632 from IPython.core import pylabtools as pt 3633 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select) File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib_inline\__init__.py:1 ----> 1 from . import backend_inline, config # noqa 3 __version__ = "0.2.1" 5 # we can't ''.join(...) otherwise finding the version number at build time requires 6 # import which introduces IPython and matplotlib at build time, and thus circular 7 # dependencies. File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib_inline\backend_inline.py:6 1 """A matplotlib backend for publishing figures via display_data""" 3 # Copyright (c) IPython Development Team. 4 # Distributed under the terms of the BSD 3-Clause License. ----> 6 import matplotlib 7 from IPython.core.getipython import get_ipython 8 from IPython.core.interactiveshell import InteractiveShell File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\__init__.py:161 157 from packaging.version import parse as parse_version 159 # cbook must import matplotlib only within function 160 # definitions, so it is safe to import from it here. --> 161 from . import _api, _version, cbook, _docstring, rcsetup 162 from matplotlib.cbook import sanitize_sequence 163 from matplotlib._api import MatplotlibDeprecationWarning File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\rcsetup.py:27 25 from matplotlib import _api, cbook 26 from matplotlib.cbook import ls_mapper ---> 27 from matplotlib.colors import Colormap, is_color_like 28 from matplotlib._fontconfig_pattern import parse_fontconfig_pattern 29 from matplotlib._enums import JoinStyle, CapStyle File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\colors.py:56 54 import matplotlib as mpl 55 import numpy as np ---> 56 from matplotlib import _api, _cm, cbook, scale 57 from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS 60 class _ColorMapping(dict): File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\scale.py:22 20 import matplotlib as mpl 21 from matplotlib import _api, _docstring ---> 22 from matplotlib.ticker import ( 23 NullFormatter, ScalarFormatter, LogFormatterSciNotation, LogitFormatter, 24 NullLocator, LogLocator, AutoLocator, AutoMinorLocator, 25 SymmetricalLogLocator, AsinhLocator, LogitLocator) 26 from matplotlib.transforms import Transform, IdentityTransform 29 class ScaleBase: File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\ticker.py:138 136 import matplotlib as mpl 137 from matplotlib import _api, cbook --> 138 from matplotlib import transforms as mtransforms 140 _log = logging.getLogger(__name__) 142 __all__ = ('TickHelper', 'Formatter', 'FixedFormatter', 143 'NullFormatter', 'FuncFormatter', 'FormatStrFormatter', 144 'StrMethodFormatter', 'ScalarFormatter', 'LogFormatter', (...) 150 'MultipleLocator', 'MaxNLocator', 'AutoMinorLocator', 151 'SymmetricalLogLocator', 'AsinhLocator', 'LogitLocator') File D:\python\Anaconda3\envs\d2l\lib\site-packages\matplotlib\transforms.py:49 46 from numpy.linalg import inv 48 from matplotlib import _api ---> 49 from matplotlib._path import ( 50 affine_transform, count_bboxes_overlapping_bbox, update_path_extents) 51 from .path import Path 53 DEBUG = False ImportError: numpy.core.multiarray failed to import
最新发布
12-02
%load_ext autoreload %autoreload 2 %matplotlib inline A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "E:\anaconda\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "E:\anaconda\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "E:\anaconda\lib\site-packages\ipykernel_launcher.py", line 17, in <module> app.launch_new_instance() File "E:\anaconda\lib\site-packages\traitlets\config\application.py", line 846, in launch_instance app.start() File "E:\anaconda\lib\site-packages\ipykernel\kernelapp.py", line 712, in start self.io_loop.start() File "E:\anaconda\lib\site-packages\tornado\platform\asyncio.py", line 199, in start self.asyncio_loop.run_forever() File "E:\anaconda\lib\asyncio\base_events.py", line 601, in run_forever self._run_once() File "E:\anaconda\lib\asyncio\base_events.py", line 1905, in _run_once handle._run() File "E:\anaconda\lib\asyncio\events.py", line 80, in _run self._context.run(self._callback, *self._args) File "E:\anaconda\lib\site-packages\ipykernel\kernelbase.py", line 510, in dispatch_queue await self.process_one() File "E:\anaconda\lib\site-packages\ipykernel\kernelbase.py", line 499, in process_one await dispatch(*args) File "E:\anaconda\lib\site-packages\ipykernel\kernelbase.py", line 406, in dispatch_shell await result File "E:\anaconda\lib\site-packages\ipykernel\kernelbase.py", line 730, in execute_request reply_content = await reply_content File "E:\anaconda\lib\site-packages\ipykernel\ipkernel.py", line 390, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "E:\anaconda\lib\site-packages\ipykernel\zmqshell.py", line 528, in run_cell return super().run_cell(*args, **kwargs) File "E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2914, in run_cell result = self._run_cell( File "E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2960, in _run_cell return runner(coro) File "E:\anaconda\lib\site-packages\IPython\core\async_helpers.py", line 78, in _pseudo_sync_runner coro.send(None) File "E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3185, in run_cell_async has_raised = await self.run_ast_nodes(code_ast.body, cell_name, File "E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3377, in run_ast_nodes if (await self.run_code(code, result, async_=asy)): File "E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3457, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "C:\Users\John\AppData\Local\Temp\ipykernel_7032\4138125057.py", line 3, in <module> get_ipython().run_line_magic('matplotlib', 'inline') File "E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 2364, in run_line_magic result = fn(*args, **kwargs) File "E:\anaconda\lib\site-packages\decorator.py", line 232, in fun return caller(func, *(extras + args), **kw) File "E:\anaconda\lib\site-packages\IPython\core\magic.py", line 187, in <lambda> call = lambda f, *a, **k: f(*a, **k) File "E:\anaconda\lib\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui) File "E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3533, in enable_matplotlib from matplotlib_inline.backend_inline import configure_inline_support File "E:\anaconda\lib\site-packages\matplotlib_inline\__init__.py", line 1, in <module> from . import backend_inline, config # noqa File "E:\anaconda\lib\site-packages\matplotlib_inline\backend_inline.py", line 6, in <module> import matplotlib File "E:\anaconda\lib\site-packages\matplotlib\__init__.py", line 109, in <module> from . import _api, _version, cbook, docstring, rcsetup File "E:\anaconda\lib\site-packages\matplotlib\rcsetup.py", line 27, in <module> from matplotlib.colors import Colormap, is_color_like File "E:\anaconda\lib\site-packages\matplotlib\colors.py", line 56, in <module> from matplotlib import _api, cbook, scale File "E:\anaconda\lib\site-packages\matplotlib\scale.py", line 23, in <module> from matplotlib.ticker import ( File "E:\anaconda\lib\site-packages\matplotlib\ticker.py", line 136, in <module> from matplotlib import transforms as mtransforms File "E:\anaconda\lib\site-packages\matplotlib\transforms.py", line 46, in <module> from matplotlib._path import ( --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) AttributeError: _ARRAY_API not found --------------------------------------------------------------------------- ImportError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_7032\4138125057.py in <module> 1 get_ipython().run_line_magic('load_ext', 'autoreload') 2 get_ipython().run_line_magic('autoreload', '2') ----> 3 get_ipython().run_line_magic('matplotlib', 'inline') E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth) 2362 kwargs['local_ns'] = self.get_local_scope(stack_depth) 2363 with self.builtin_trap: -> 2364 result = fn(*args, **kwargs) 2365 return result 2366 E:\anaconda\lib\site-packages\decorator.py in fun(*args, **kw) 230 if not kwsyntax: 231 args, kw = fix(args, kw, sig) --> 232 return caller(func, *(extras + args), **kw) 233 fun.__name__ = func.__name__ 234 fun.__doc__ = func.__doc__ E:\anaconda\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k) 185 # but it's overkill for just that one bit of state. 186 def magic_deco(arg): --> 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg): E:\anaconda\lib\site-packages\IPython\core\magics\pylab.py in matplotlib(self, line) 97 print("Available matplotlib backends: %s" % backends_list) 98 else: ---> 99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui) 100 self._show_matplotlib_backend(args.gui, backend) 101 E:\anaconda\lib\site-packages\IPython\core\interactiveshell.py in enable_matplotlib(self, gui) 3531 """ 3532 from IPython.core import pylabtools as pt -> 3533 from matplotlib_inline.backend_inline import configure_inline_support 3534 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select) 3535 E:\anaconda\lib\site-packages\matplotlib_inline\__init__.py in <module> ----> 1 from . import backend_inline, config # noqa 2 __version__ = "0.1.6" # noqa E:\anaconda\lib\site-packages\matplotlib_inline\backend_inline.py in <module> 4 # Distributed under the terms of the BSD 3-Clause License. 5 ----> 6 import matplotlib 7 from matplotlib import colors 8 from matplotlib.backends import backend_agg E:\anaconda\lib\site-packages\matplotlib\__init__.py in <module> 107 # cbook must import matplotlib only within function 108 # definitions, so it is safe to import from it here. --> 109 from . import _api, _version, cbook, docstring, rcsetup 110 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence 111 from matplotlib.cbook import mplDeprecation # deprecated E:\anaconda\lib\site-packages\matplotlib\rcsetup.py in <module> 25 from matplotlib import _api, cbook 26 from matplotlib.cbook import ls_mapper ---> 27 from matplotlib.colors import Colormap, is_color_like 28 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern 29 from matplotlib._enums import JoinStyle, CapStyle E:\anaconda\lib\site-packages\matplotlib\colors.py in <module> 54 import matplotlib as mpl 55 import numpy as np ---> 56 from matplotlib import _api, cbook, scale 57 from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS 58 E:\anaconda\lib\site-packages\matplotlib\scale.py in <module> 21 import matplotlib as mpl 22 from matplotlib import _api, docstring ---> 23 from matplotlib.ticker import ( 24 NullFormatter, ScalarFormatter, LogFormatterSciNotation, LogitFormatter, 25 NullLocator, LogLocator, AutoLocator, AutoMinorLocator, E:\anaconda\lib\site-packages\matplotlib\ticker.py in <module> 134 import matplotlib as mpl 135 from matplotlib import _api, cbook --> 136 from matplotlib import transforms as mtransforms 137 138 _log = logging.getLogger(__name__) E:\anaconda\lib\site-packages\matplotlib\transforms.py in <module> 44 45 from matplotlib import _api ---> 46 from matplotlib._path import ( 47 affine_transform, count_bboxes_overlapping_bbox, update_path_extents) 48 from .path import Path ImportError: numpy.core.multiarray failed to import
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值