MATLAB | MATLAB不会画图?官方团队来教你

article/2025/6/7 16:31:00

让我看看是哪个小傻瓜还没用过MATLAB官方gallery,常见的图直接MATHWORKS搜索一下就能找到,一些有意思的组合图,以及一些特殊属性的设置MATHWORKS官方是有专门去整理的,虽然一些很特殊的图还是没有(哈哈哈弦图小提琴图啥的官方没有的我自己大部分都写过补充过),但是也依旧足够收获很多了!!

MATLAB Plot Gallery

地址:
https://ww2.mathworks.cn/products/matlab/plot-gallery.html?s_tid=srchtitle_gallery_1

其中有超超超多优秀绘图案例:

点击launch example甚至可以在线运行例子,优秀!

点击左侧download code可以下载全部代码及数据:

有的程序运行时会提示你没有数据,你下载的文件包内就有一个名为Data Sets的文件夹。把文件夹里的mat文件复制过去即可:

这里随便两个例子运行:

load BostonTemp.mat
yearIdx = 13;      % Choose the starting year to visualize the monthly temperature for five years.
TempData5Years = Temperatures(yearIdx:yearIdx+4,:);
barWidth = 0.5;
figure
b = bar3(TempData5Years,barWidth);      % Specify bar width in the third argumentfor k = 1:length(b)zdata = b(k).ZData;                 % Use ZData property to create color gradientb(k).CData = zdata;                 % Set CData property to Zdatab(k).FaceColor = "interp";          % Set the FaceColor to 'interp' to enable the gradient 
end
title(sprintf("Average Monthly Temperatures from %d to %d",Year(yearIdx),Year(yearIdx+4)))
xlabel("Month")
ylabel("Year")
zlabel("Temperature (\circF)")xticklabels(Months)
yticklabels(Year(yearIdx):Year(yearIdx+4))box on

load("rideData.mat")faceColorType = "flat";
h2 = histogram2(rideData.Duration, rideData.birth_date,..."FaceColor",faceColorType);                                          % Specify the bar color schemetitle("Ride counts based on ride length and the age of the rider")
xlabel("Length of Ride")
ylabel("Birth Year")
zlabel("Number of Rides")
view(17,30)colormap("turbo"); % Specify colormap

[r,theta,x,y,streamline,pressure] = flowAroundCylinder();contourLevels = 20; 
LineWidth = 1; [~,c] = contourf(x,y,pressure,...contourLevels,...              % Specify a scalar integer number of contour levels"LineWidth",LineWidth);        % Specify the contour line widthaxis([-5, 5,...     % x-axis limits -5, 5]);      % y-axis limits 
circle(0,0,1);      % Call helper function to plot circlexlabel("x/R")
ylabel("y/R")
title("Flow pressure over cylinder")set(gca,..."FontSize",15,...           % Set font size"FontAngle","italic");      % Italicize fontcolormap("turbo");    % Specify a colormap to use in the contourf plot
cb = colorbar;                  
cb.Ticks = cb.Limits;                    
cb.TickLabels = ["High" "Low"];  % Specify labels for colorbarfunction [r,theta,x,y,streamline,pressure] = flowAroundCylinder()
V_i = 1000;
a = 1;
theta = linspace(0,2*pi,100); 
rr = linspace(a,10*a,100);        
[t,r] = meshgrid(theta,rr);                        % create meshgrid in two dimensions
[x,y] = pol2cart(t,r);                             % converts polar to cartesian coordinates
streamline = V_i.*sin(t).*r.*(1-(a^2./(r.^2)));      % Creation of the streamline function
pressure = 2*(a.^2./r.^2).*cos(2.*t)-(a.^4./r.^4); % static pressure around the cylinder
endfunction h = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit,"-k","LineWidth",2);
hold off
end

MathWorks Plot Gallery Team

上面那些学完了没学够怎么办??MATHWORKS官方团队MathWorks Plot Gallery Team还在fileexchange上上传了大量例子:

地址:
https://ww2.mathworks.cn/matlabcentral/profile/authors/3166380

依旧有非常多优秀例子:

随便点开一个再点击右侧下载即可:

下载完直接就可以运行,以下依旧举几个例子:

%%
% *This is an example of creating area charts, bar charts, and pie charts with some annotation in MATLAB®* .
% 
% You can open this example in the <https://www.mathworks.com/products/matlab/live-editor.html 
% Live Editor> with MATLAB version 2016a or higher.
%
% Read about the <http://www.mathworks.com/help/matlab/ref/fill.html |fill|>, <http://www.mathworks.com/help/matlab/ref/bar.html |bar|>, <http://www.mathworks.com/help/matlab/ref/text.html |text|>, and <http://www.mathworks.com/help/matlab/ref/pie.html |pie|> functions in the MATLAB documentation.
% For more examples, go to <http://www.mathworks.com/discovery/gallery.html MATLAB Plot Gallery>
%
% Copyright 2012-2018 The MathWorks, Inc.% Set up data
t  = 0:0.01:2*pi;
x1 = -pi/2:0.01:pi/2;
x2 = -pi/2:0.01:pi/2;
y1 = sin(2*x1);
y2 = 0.5*tan(0.8*x2);
y3 = -0.7*tan(0.8*x2);
rho = 1 + 0.5*sin(7*t).*cos(3*t);
x = rho.*cos(t);
y = rho.*sin(t);% Create the left plot (filled plots, errorbars, texts)
figure
subplot(121)
hold on
h(1) = fill(x, y, [0 .7 .7]);
set(h(1), 'EdgeColor', 'none')h(2) = fill([x1, x2(end:-1:1)], [y1, y2(end:-1:1)], [.8 .8 .6]);
set(h(2), 'EdgeColor', 'none')h(3) = line(x1, y1, 'LineWidth', 1.5, 'LineStyle', ':');
h(4) = line(x2, y2, 'Linewidth', 1.5, 'LineStyle', '--', 'Color', 'red');
h(5) = line(x2, y3, 'Linewidth', 1.5, 'LineStyle', '-.', 'Color', [0 .5 0]);% Create error bars
err = abs(y2-y1);
hh = errorbar(x2(1:15:end), y3(1:15:end), err(1:15:end), 'r');
h(6) = hh(1);% Create annotations
text(x2(15), y3(15), '\leftarrow \psi = -.7tan(.8\theta)', ...'FontWeight', 'bold', 'FontName', 'times-roman', ...'Color', [0 0.5 0], 'FontAngle', 'italic')
text(x2(10), y2(10),'\leftarrow \psi = .5tan(.8\theta)', ...'FontWeight', 'bold', 'FontName', 'times-roman',...'Color', 'red', 'FontAngle', 'italic')text(0, -1.65, 'Text box', 'EdgeColor', [.3 0 .3], ...'HorizontalAlignment', 'center', ...'VerticalAlignment', 'middle', 'LineStyle', ':', ...'FontName', 'palatino', 'Margin', 4, 'BackgroundColor', [.8 .8 1], ...'LineWidth', 1)% Adjust axes properties
axis equal
set(gca, 'Box', 'on', 'LineWidth', 1, 'Layer', 'top', ...'XMinorTick', 'on', 'YMinorTick', 'on', 'XGrid', 'off', 'YGrid', 'on', ...'TickDir', 'out', 'TickLength', [.015 .015], 'XLim', x1([1,end]),...'FontName', 'avantgarde', 'FontSize', 10, 'FontWeight', 'normal', ...'FontAngle', 'italic')xlabel('theta (\theta)', 'FontName', 'bookman', 'FontSize', 12, ...'FontWeight', 'bold')
ylabel('value(\Psi)', 'FontName', 'helvetica', 'FontSize', 12, ...'FontWeight', 'bold', 'FontAngle', 'normal')
title('Cool Plot', 'FontName','palatino', 'FontSize', 18, ...'FontWeight', 'bold', 'FontAngle', 'italic', 'Color', [.3 .3 0])
legh = legend(h, 'blob', 'diff', 'sin(2\theta)', 'tan', 'tan2', 'error');
set(legh, 'FontName', 'helvetica', 'FontSize', 8, 'FontAngle', 'italic')% Create the upper right plot (bar chart)
subplot(222)
bar(rand(10,5), 'stacked')
set(gca, 'Box', 'on', 'LineWidth', .5, 'Layer', 'top', ...'XMinorTick', 'on', 'YMinorTick', 'on', 'XGrid', 'on', 'YGrid', 'on', ...'TickDir', 'in', 'TickLength', [.015 .015], 'XLim', [0 11], ...'FontName', 'helvetica', 'FontSize', 8, 'FontWeight', 'normal', ...'YAxisLocation', 'right')
xlabel('bins', 'FontName', 'avantgarde', 'FontSize', 10, ...'FontWeight', 'normal')
yH = ylabel('y val (\xi)', 'FontName', 'bookman', 'FontSize', 10, ...'FontWeight', 'normal');
set(yH, 'Rotation', -90, 'VerticalAlignment', 'bottom')
title('Bar Graph', 'FontName', 'times-roman', 'FontSize', 12, ...'FontWeight', 'bold', 'Color', [0 .7 .7])% Create the bottom right plot (pie chart)
subplot(224)
pie([2 4 3 5], {'North', 'South', 'East', 'West'})
tP = get(get(gca, 'Title'), 'Position');
set(get(gca, 'Title'), 'Position', [tP(1), 1.2, tP(3)])
title('Pie Chart', 'FontName', 'avantgarde', 'FontSize', 12, ...'FontWeight', 'bold', 'FontAngle', 'italic', 'Color', [.7 0 .7])
th = findobj(gca, 'Type', 'text');
set(th, 'FontName', 'bookman', 'FontWeight', 'bold', 'FontAngle', 'italic')

%%
% *This is an example of how to customize a plot to make them publication quality in MATLAB&#174;* .
%
% You can open this example in the <https://www.mathworks.com/products/matlab/live-editor.html 
% Live Editor> with MATLAB version 2016a or higher.
%
% For more examples, go to <http://www.mathworks.com/discovery/gallery.html MATLAB Plot Gallery>
%
% Copyright 2012-2018 The MathWorks, Inc.% Load data
load data xfit yfit xdata_m ydata_m ydata_s xVdata yVdata xmodel ymodel ...ymodelL ymodelU c cint% Create basic plot
figure
hold on
hFit = line(xfit  , yfit);
hE = errorbar(xdata_m, ydata_m, ydata_s);
hData = line(xVdata, yVdata);
hModel = line(xmodel, ymodel);
hCI(1) = line(xmodel, ymodelL);
hCI(2) = line(xmodel, ymodelU);% Adjust line properties (functional)
set(hFit, 'Color', [0 0 .5])
set(hE, 'LineStyle', 'none', 'Marker', '.', 'Color', [.3 .3 .3])
set(hData, 'LineStyle', 'none', 'Marker', '.')
set(hModel, 'LineStyle', '--', 'Color', 'r')
set(hCI(1), 'LineStyle', '-.', 'Color', [0 .5 0])
set(hCI(2), 'LineStyle', '-.', 'Color', [0 .5 0])% Adjust line properties (aesthetics)
set(hFit, 'LineWidth', 2)
set(hE, 'LineWidth', 1, 'Marker', 'o', 'MarkerSize', 6, ...'MarkerEdgeColor', [.2 .2 .2], 'MarkerFaceColor' , [.7 .7 .7])
set(hData, 'Marker', 'o', 'MarkerSize', 5, ...'MarkerEdgeColor', 'none', 'MarkerFaceColor', [.75 .75 1])
set(hModel, 'LineWidth', 1.5)
set(hCI(1), 'LineWidth', 1.5)
set(hCI(2), 'LineWidth', 1.5)% Add labels
hTitle = title('My Publication-Quality Graphics');
hXLabel = xlabel('Length (m)');
hYLabel = ylabel('Mass (kg)');% Add text
hText = text(10, 800, ...sprintf('{\\itC = %0.1g \\pm %0.1g (CI)}', c, cint(2)-c));% Add legend
hLegend = legend([hE, hFit, hData, hModel, hCI(1)], ...'Data ({\it\mu} \pm {\it\sigma})', 'Fit (C{\itx}^3)', ...'Validation Data', 'Model (C{\itx}^3)', '95% CI', ...'Location', 'NorthWest');% Adjust font
set(gca, 'FontName', 'Helvetica')
set([hTitle, hXLabel, hYLabel, hText], 'FontName', 'AvantGarde')
set([hLegend, gca], 'FontSize', 8)
set([hXLabel, hYLabel, hText], 'FontSize', 10)
set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')% Adjust axes properties
set(gca, 'Box', 'off', 'TickDir', 'out', 'TickLength', [.02 .02], ...'XMinorTick', 'on', 'YMinorTick', 'on', 'YGrid', 'on', ...'XColor', [.3 .3 .3], 'YColor', [.3 .3 .3], 'YTick', 0:500:2500, ...'LineWidth', 1)

%%
% *This is an example of creating a chart of built-in colormaps in MATLAB&#174;* .
% 
% You can open this example in the <https://www.mathworks.com/products/matlab/live-editor.html 
% Live Editor> with MATLAB version 2016a or higher.
%
% Read about the <http://www.mathworks.com/help/matlab/ref/colormap.html |colormap|> function in the MATLAB documentation.
% For more examples, go to <http://www.mathworks.com/discovery/gallery.html MATLAB Plot Gallery>
%
% Copyright 2012-2018 The MathWorks, Inc.% Define built-in colormaps
maps = {};
if exist('parula', 'file')maps = {'parula'};
end
maps = [maps 'jet', 'hsv', 'hot', 'cool', 'spring', 'summer', 'autumn', ...'winter', 'gray', 'bone', 'copper', 'pink', 'lines'];% Number of color levels to create
nLevels = 16;figure% X data points for color patches
xData = [linspace(0, 15, nLevels); linspace(1, 16, nLevels); ...linspace(1, 16, nLevels); linspace(0, 15, nLevels)];% Create each color bar
for iMap = 1:length(maps)offset = 2*(length(maps) - iMap);yData = [zeros(2, nLevels); 1.5*ones(2, nLevels)] + offset;% Construct appropriate colormap.cData = feval(maps{iMap}, nLevels);% Display colormap chartpatch('XData', xData, 'YData', yData, ...'EdgeColor', 'none', ...'FaceColor', 'flat', ...'FaceVertexCData', cData)rectangle('Position', [0, offset, 16, 1.5], ...'Curvature', [0 0])text(16, offset, sprintf(' %s', maps{iMap}), ...'VerticalAlignment', 'bottom', ...'FontSize', 12)
endaxis equal off
title('Built-in Colormaps')

图形示例

如果是刚入门的选手,觉得上面那些都太难怎么办??基础入门图形示例模块来啦~

地址:
https://ww2.mathworks.cn/help/matlab/examples.html?category=graphics&exampleproduct=all&s_tid=CRUX_lftnav

更多的基础教程!!

继续随便运行点示例,美滋滋:

Z = peaks(100);
zmin = floor(min(Z(:))); 
zmax = ceil(max(Z(:)));
zinc = (zmax - zmin) / 40;
zlevs = zmin:zinc:zmax;figure
contour(Z,zlevs)zindex = zmin:2:zmax;hold on
contour(Z,zindex,'LineWidth',2)
hold off

x = 0:0.2:10;                     
y = besselj(0, x);xconf = [x x(end:-1:1)] ;         
yconf = [y+0.15 y(end:-1:1)-0.15];figure
p = fill(xconf,yconf,'red');
p.FaceColor = [1 0.8 0.8];      
p.EdgeColor = 'none';           hold on
plot(x,y,'ro')
hold off

MATLAB样本数据集

想找点示例数据练练手??来瞅瞅MATLAB都有那些自带数据集吧!

地址:
https://ww2.mathworks.cn/help/matlab/import_export/matlab-example-data-sets.html

包含了MATLAB内置数据集及其介绍:

当然也可以通过命令行窗口运行以下代码进入demos文件夹:

winopen(fullfile(matlabroot,'toolbox','matlab','demos'))

如果下载过Statistics and Machine Learning Toolbox工具箱,那么会额外拥有一些这个工具箱内置的数据:

地址:
https://ww2.mathworks.cn/help/stats/sample-data-sets.html

测试矩阵gallery

想要画好图怎么能不熟练掌握各种特殊矩阵?
没错MATLAB还有官方测试矩阵gallery

地址:
https://ww2.mathworks.cn/help/matlab/ref/gallery.html?searchHighlight=gallery&s_tid=srchtitle_gallery_1

比如说创建一个11阶循环矩阵:

C=gallery('circul',11);imagesc(C)
axis square
colorbar

通过循环矩阵计算复平面上的特征值分布:

E = zeros(18,20000);rng('default')
for i = 1:20000x = -0.4 + 0.8*randi([0 1],1,18);A = gallery('circul',x);E(:,i) = eig(A);
endscatter(real(E(:)),imag(E(:)),'b.')
xlabel('Re(E)')
ylabel('Im(E)')
xlim([-3 3])
ylim([-3 3])
axis square

11阶minij矩阵:

M=gallery('minij',11);imagesc(M)
axis square
colorbar

Chebyshev 谱微分矩阵:

C=gallery('chebspec',11,0);imagesc(C)
axis square
colorbar

矩阵条件数估计量的反例:

C=gallery('condex',11);imagesc(C)
axis square
colorbar

上面这些都学完我就不信还有人不会绘图hiahiahia


http://chatgpt.dhexx.cn/article/Z8p92Q9c.shtml

相关文章

SAR成像概述

SAR成像专栏目录https://blog.csdn.net/lightninghenry/article/details/122393577 本文目录: 1. 发展概述 2.SAR的工作模式 2.1条

结构光3D成像原理及应用

点击上方“小白学视觉”&#xff0c;选择加"星标"或“置顶” 重磅干货&#xff0c;第一时间送达之前给大家介绍了TOF 与双目结构光的对比&#xff0c;那在深度相机的应用方案种还有结构光的摄像方案。今天小编就跟大家来聊一聊结构光&#xff0c;顺便也捋一捋这三者的…

光场在多显微成像中的应用

光场成像技术的发展为显微成像提供了新的思路&#xff0c;通过对二者进行结合可以实现对微观物体的三维信息和光学信息的获取。 2006年&#xff0c;Levoy和Ng[1]等人在传统光学显微系统的中继成像面上插入一块能够捕获光场信息的微透镜阵列&#xff0c;搭建了世界上第一台光场…

齐岳提供NIR近红外二区染料 TTQ-TF、TTQ-TTF、 TTQ-PLL、TTQ-F 、TTQ-TF、TTQ-TPA、 TTQ-PLL、TTQ-TC用于化疗-光热联合治疗

齐岳提供NIR近红外二区染料 TTQ-TF、TTQ-TTF、 TTQ-PLL、TTQ-F 、TTQ-TF、TTQ-TPA、 TTQ-PLL、TTQ-TC用于化疗-光热联合治疗 近年来&#xff0c;光学成像介导的化疗-光热联合疗法正成为一种有潜力的癌症治疗策略。在光学成像中&#xff0c;相比于近红外一区荧光成像 (650-900 n…

【边缘检测】用于体积三维数据的差分精尖边缘检测研究(Matlab代码实现)

&#x1f468;‍&#x1f393;个人主页&#xff1a;研学社的博客 &#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思…

由光声前向模型求取光声信号

在相关论文中&#xff0c;提到一种使用光声前向模型来求取输入信号&#xff0c;根据公式 &#xff0c;其中A为论文《Acceleration of Optoacoustic Model-Based Reconstruction Using Angular Image Discretization》提出的模型矩阵。P为从ROI中像素位置所吸收的能量计算一组瞬…

共轭高分子纳米颗粒造影剂/葡聚糖包裹的超顺磁性Fe3O4纳米颗/稀土化合物核磁共振成像(MRI)-齐岳

共轭高分子纳米颗粒造影剂/葡聚糖包裹的超顺磁性Fe3O4纳米颗/稀土化合物核磁共振成像(MRI)-齐岳 体外造影剂辅助的近红外二区光声显微成像技术可以解析三维广面积/大深度&#xff0c;高信号/背景比例&#xff0c;高成像深度/深度分辨率比例的生物组织。 具有强近红外二区吸光…

关于超声和光声中的延迟求和算法的详细说明 Detail description of DAS algorithm

关于超声和光声中的延迟求和算法的详细说明 Detail description of DAS algorithm 背景 background存在问题&#xff08;个人思考&#xff09;算法说明及代码示例 背景 background In LED-base Photoacoustic imaging,DAS algorithm was always used for the image reconstruc…

前置微小信号放大器在光声技术的血管识别研究中的应用

实验名称&#xff1a;前置微小信号放大器在光声技术的血管识别研究中的应用 研究方向&#xff1a;生物识别技术 测试目的&#xff1a; 利用MATLAB对光声血管进行识别&#xff1a;1、对光声血管图库的图像进行预处理包括归一化、二值化、平滑、细化和毛刺修剪得到细化图像&#…

光学分辨率光声显微镜中基于深度学习的运动校正算法

在这项研究中&#xff0c;我们提出了一种基于深度学习的方法来校正光学分辨率光声显微镜 (OR-PAM) 中的运动伪影。该方法是一种卷积神经网络&#xff0c;它从具有运动伪影的输入原始数据建立端到端映射&#xff0c;以输出校正后的图像。首先&#xff0c;我们进行了仿真研究&…

双光子成像和近红外二区荧光共聚焦成像/树状大分子CT/MRI双模态成像造影剂/锰螯合物磁共振成像(MRI)

双光子成像和近红外二区荧光共聚焦成像/树状大分子CT/MRI双模态成像造影剂/锰螯合物磁共振成像(MRI) 我们使用 PTD 纳米颗粒实现了透过老鼠头骨脑血管的三维高分辨(分辨率 25.4 微米),高信号/背景比例( 22.3 dB)成像. 其成像深度高达 1001 微米. 该脑血管光声成像效果比较近报道…

材料参数分段恒定的定量光声层析成像(Matlab代码实现)

&#x1f468;‍&#x1f393;个人主页&#xff1a;研学社的博客 &#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思…

近红外硅量子点波长500nm左右|锗量子点GeQDs.光热效果性能优异,可用于光热成像治疗光声成像,载药

近红外硅量子点波长500nm左右 硅量子点由于具有优异的发光特性,能够应用于光电器件和生物成像等领域。本征硅量子点的性质显著依赖于其尺寸大小和表面状况。同时,作为半导体材料,掺杂是调控硅量子点性质的另一个维度。通过掺杂研究人员可以对硅量子点的光学、电学、磁学等性能…

AD采集卡用于光声成像

光声成像是一种新的成像方式&#xff0c;它继承了光成像和声成像的优点&#xff0c;能够有效的进行生物组织结构和功能成像&#xff0c;为研究生物组织的形态结构&#xff0c;生理特征&#xff0c;病理特征&#xff0c;代谢功能等提供了重要的手段&#xff0c;特别适合于癌症的…

2022-2028年中国光声成像系统行业市场调研分析及发展规模预测报告

本研究报告数据主要采用国家统计数据&#xff0c;海关总署&#xff0c;问卷调查数据&#xff0c;商务部采集数据等数据库。其中宏观经济数据主要来自国家统计局&#xff0c;部分行业统计数据主要来自国家统计局及市场调研数据&#xff0c;企业数据主要来自于国统计局规模企业统…

光声断层成像的傅里叶变换图像重建算法

快速傅里叶变换光声断层图像重建 前言 光声成像的基本原理是利用短脉宽的脉冲激光器激发组织中的吸收体产生光声信号&#xff0c;再结合相应的图像重建算法例如MIP&#xff0c;FBP和FFT&#xff08;最大值投影算法&#xff0c;滤波反投影重建算法&#xff0c;傅里叶变换&#…

光声成像

文章目录 1.光声成像简介2.光声成像分类3.图像重建算法4.光声成像系统三个典型问题5.挑战 光声成像之前的成像方式对比 X射线成像&#xff1a; 优点&#xff1a;能对骨头和硬组织进行深度成像&#xff0c;有着很强的对比度和极高的分辨率 缺点&#xff1a;对软组织成像很差&…

Python 爬取网页信息并保存到本地爬虫爬取网页第一步【简单易懂,注释超级全,代码可以直接运行】

Python 爬取网页信息并保存到本地【简单易懂&#xff0c;代码可以直接运行】 功能&#xff1a;给出一个关键词&#xff0c;根据关键词爬取程序&#xff0c;这是爬虫爬取网页的第一步 步骤&#xff1a; 1.确定url 2.确定请求头 3.发送请求 4.写入文件 确定请求头是其中的关键一…

Python爬取网页的所有内外链

用Python爬虫&#xff0c;爬取网页的所有内外链 项目介绍代码大纲 网站详情代码详情队列内链外链请求头 完整代码爬取结果 项目介绍 采用广度优先搜索方法获取一个网站上的所有外链。 首先&#xff0c;我们进入一个网页&#xff0c;获取网页的所有内链和外链&#xff0c;再分别…

python学习笔记(三)---python爬取网页指定内容

python学习笔记&#xff08;三&#xff09;—python爬取网页指定内容 1、利用正则匹配爬取指定内容&#xff0c;例如标题 正则表达式&#xff1a; <title>(.*?)</title> req urllib.request.Request(urlurl,headersheaders) content urllib.request.urlopen(re…