使用backtrader时遇到的matplotlib版本过高的问题及解决办法

在使用backtrader进行金融数据分析和策略回测时,我们可能会遇到一个常见的问题,那就是matplotlib版本过高导致backtrader无法正常运行。本文将介绍如何解决这个问题,并提供相应的源代码和描述,帮助读者顺利使用backtrader进行数据分析和策略回测。

问题描述:
当我们在安装并使用backtrader时,可能会遇到以下错误提示之一:

ModuleNotFoundError: No module named 'matplotlib'

或者

AttributeError: ‘FigureCanvasGTK3Cairo’ object has no attribute ‘get_default_filename’

这些错误提示表明我们当前的matplotlib版本过高,不兼容backtrader的要求。

问题原因:
backtrader的早期版本与matplotlib存在一些兼容性问题,特别是在matplotlib 3.4及更高版本中。当我们安装了较新版本的matplotlib时,backtrader可能无法正常引用matplotlib的相关功能,导致出现上述错误。

解决办法:
为了解决这个问题,我们需要降低matplotlib的版本。请按照以下步骤操作:

步骤1:卸载当前版本的matplotlib
在命令行中执行以下命令,卸载当前版本的matplotlib:

pip uninstall matplotlib
Backtrader 文档学习- Plotting plot 绘图功能,绘图选项参数,控制对象的参数,plotscheme 对象。 阅读详情

相关推荐

Backtrader无法支持最新版本的Matplotlib,如何解决以及使用Backtrader进行画图的方案

Backtrader早期的版本是基于Matplotlib v1.x开发的,而随着时间的推移,Matplotlib已经迭代到了v3.x。在这个过程中,Matplotlib引入了一些不兼容的更改,导致了与Backtrader的兼容性问题。总结而言,当Backtrader无法支持最新版本的Matplotlib时,你可以选择降级安装兼容的Matplotlib版本,或者使用Backtrader自带的绘图功能。这样一来,你无需依赖于外部的Matplotlib库,就可以使用Backtrader自带的绘图功能进行画图。

NisyPhilosophy的博客 708

Backtrader无法支持最新版本的Matplotlib,解决方案及Backtrader绘图的方法

根据你的需求和偏好,选择适合的解决方案来解决Backtrader与Matplotlib版本不兼容的问题。Backtrader的早期版本使用的是Matplotlib的pyplot模块来绘制图形。然而,由于Matplotlib的更新,最新版本的Matplotlib中的pyplot模块与Backtrader不兼容。如果你无法解决Backtrader与Matplotlib版本不兼容的问题,你可以考虑使用其他绘图库来替代Matplotlib。一种解决方案是使用与Backtrader兼容的Matplotlib版本。

InUnix的博客 885

【答读者问27】backtrader不支持最新版本的matplotlib怎么办以及backtrader画图的解决方案

backtrader的版本由于相对比较完善了,所以最近更新的比较慢,这就导致了一个问题,如果依赖的模块进行更新了,就可能导致backtrader的某些功能不可用,即版本兼容问题。比如,当使用最新版本的matplotlib的时候,在backtrader中,使用cerebro.plot()进行画图会保持,出现兼容问题,如果把matplotlib的版本进行倒退到3.1.2,就可以使用了。 简单点的解决方式 直接尝试把matplotlib的版本倒退到3.1.2 这种向后兼容的方式是不合理的,但是可以作为权宜之计

云金杞 3708

matplotlib-2.1.0

本人在大家深度学习框架tensorflow过程中使用的软件,方便大家使用

Python3.x+matplotlib(matplotlib版本好像是2.2.1及以上版本;反正要求较高版本)库实现三维网格彩色显示源代码

Python3.x+matplotlib(matplotlib版本好像是2.2.1及以上版本;反正要求较高版本)库实现三维网格彩色显示源代码

抖音自定义卡片链接(图文链接)

抖音自定义可以自定义标题,打开链接,和展示图片 效果 主要代码 public void sendMessage(String conversationId, Object aBaseContent) throws Exception { // C233282u5.LIZIZ.LIZ().LIZIZ(LIZ).LIZ(obtain).LIZ(hLn).LIZ((AbstractC59811HHc) new H9Q()); Object HOa = ReflectionUtil

傅恒的博客 4144

Ubuntu24.04下Librenms的完整安装与配置指南

本文提供了在Ubuntu 24.04 LTS系统上完整安装与配置LibreNMS网络监控系统的详细指南。内容涵盖系统环境准备、依赖安装、源码获取、PHP/数据库/Nginx配置、Composer安装、网页向导设置以及设备添加与日常使用,帮助用户快速部署一套功能强大的开源网络监控解决方案。

tgb3456789的博客 1150

0032期基于深度学习的大米识别-含数据集

083基于深度学习的手势识别小程序版本_含10多种模型包括alexnet、DenseNet、DLA、GoogleNet、Mobilenet、ResNet、ResNeXt、ShuffleNet、VGG、EfficientNet和Swin transformer等10多种模型。117nlp自然语言处理-文本情感分类-joy-sadness-anger-fear-love-surprise。运行02深度学习模型训练.py就会将txt文本中记录的训练集和验证集进行读取训练,训练好后会保存模型在本地。

grehtsfrs的博客 1512

Android车载桌面开发实战:从CarLauncher源码解析到自定义Launcher开发(Android 11)

本文深入解析了Android 11中CarLauncher的源码架构与核心模块,并提供了从零开始定制开发车载Launcher的完整实战指南。内容涵盖车载桌面的独特定位、驾驶场景优化、多屏协同、动态内容嵌入等核心挑战,以及如何构建符合安全规范、体验流畅的自定义车载桌面应用,是车载应用开发者提升系统级定制能力的实用参考。

weixin_29266647的博客 525

Appsflyer S2S事件上报实战:从参数获取到避坑指南(附Firebase对比)

本文详细解析了Appsflyer S2S事件上报的实战技巧,包括核心参数获取、测试环境搭建、生产环境最佳实践以及高级场景处理。通过对比Firebase的事件上报机制,帮助开发者高效避坑并优化数据上报流程,提升应用分析与营销效果。

egg99的博客 889

开源GIS -- 笔记

基础开发库 数据读写:GDAL/OGR(C/C++) ArcGIS和GE都是使用此工具 投影转换:Proj.4(C/C++) 拓扑计算:JTS(Java),GEOS(C++),Shapely(python) 组件式开发库 GeoTools(Java),DotSpatial(.NET) 空间分析: Scipy(通用科学计算、方程求解), numpy,NextworkX, rPy(统计分析), Scikit-learn,pysal(空间分析) 深度学习: Keras、 tensorflow、 pytor

DZ Space 4521

基于 DnLUT 超高效的彩色图像去噪(CVPR 2025),本地部署 DnLUT 模型,图像去噪算法训练和推理,全网最详细教程

基于 DnLUT 超高效的彩色图像去噪(CVPR 2025),本地部署 DnLUT 模型,图像去噪算法训练和推理,全网最详细教程

在职AI算法工程师,擅长计算机视觉,YOLO目标检测、分割等,擅长web、pyqt界面可视化,好内容持续更新中,来这里跟大家一起学习,共同进步 372

【即插即用模块】Transformer篇 | ICCV 2025 | MALA :注意力分布神似Softmax,告别线性注意力性能短板!

MALA(Magnitude-Aware Linear Attention)是一种改进的线性注意力机制,通过引入缩放因子和偏移项,解决了传统线性注意力忽视查询幅度的问题,使其分布更接近Softmax Attention。该模块具有线性复杂度(O(n)),结合RoPE和LEPE编码实现全局-局部位置信息混合,通过z值调制平衡信息权重。实验表明MALA在轻量级视觉任务中能有效平衡效率与精度,注意力可视化显示其分布与Softmax Attention高度相似。代码提供完整的RoPE位置编码和线性注意力

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 1112

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 在肯特纳通道策略中应用到鸡蛋期货的文章
下一篇: Backtrader基础教程:使用Volume Filling Fillers
普通网友
博客等级 码龄3年 209粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值