文章目录
- 引言
- 折线图
- 带误差棒得折线图
- 单个带误差棒得折线图
- 立体饼图
- 完整复现代码
引言
美赛的绘图是非常重要得,这篇文章给大家分享我自己复现2024年美赛O奖优秀论文得代码,基于Matalab来实现,可以直接运行出图。
折线图
% MATLAB 官方整理
%https://ww2.mathworks.cn/products/matlab/plot-gallery.html?s_tid=srchtitle_gallery_1
% 绘图案例
%% 折线图
%% 图框的基本设置
clc;clear;close all;
load('color_list.mat')
load('折线图测试数据.mat')
figure('Position',[100,100,600,400]) %整个框大小设置
x1=[1:100];
y1=2*x1+10*rand(1,length(x1));
y2=0.01*x1.^2+0.5*x1+10*rand(1,length(x1));
color_index=[1,3,4,7,8,9]; %颜色选取
fu={'-*','-^','-o','-d','-p'}; %符号
% %单根折线图
% plot(x1,y1,'--','LineWidth',2,'Color',color_list(color_index(1),:))
% hold on %保持在一个图窗内
% plot(x1,y2,'--','LineWidth',2,'Color',color_list(color_index(2),:))
% hold on
color_set=[0.1451 0.6118 0.1451;1.0000 0.4980 0.0549];
% 单根折线图
plot(x1,y1,'--','LineWidth',2,'Color',color_set(1,:))
hold on %保持在一个图窗内
plot(x1,y2,'-','LineWidth',1.5,'Color',color_set(2,:))
hold on
xlabel('time')
ylabel('value')
title('title')
xticks([10:20:100]);
% xticks([10,30,50,70,90]);
xticklabels({'1-10','1-20','2-10','2-20','3-10'})
%图框全框或者半框的设置
box off
%box on
% x轴和y轴的范围设置
% xlim([0,100])
% ylim([0,100])
%直线的设置
xline(30,'--','LineWidth',1.2)
yline(30)
%网格的设置
% grid("on")
% set(gca,'XGrid','on',GridLineStyle',':','GridColor','k','GridAlpha',1);
% set(gca,'xgrid','on');
% set(gca,'ygrid','on');
legend('sybol1','sybol2')
legend('Box','off')
set(gca,'FontName','Times New Roman',"FontSize",12,"LineWidth",1.2)
带误差棒得折线图
%% 带误差棒的折线图
clc;clear;close all;
load('color_list.mat')
color=[0.611764705882353,0.207843137254902,0.560784313725490;0.301960784313725,...
0.164705882352941,0.458823529411765;0.556862745098039,0.549019607843137,0.549019607843137];
% index=[1,30,40];
% color=color_list(index,:);
% data_test=[1,2,3;1.1,1.9,2.9;1.2,2.1,3.1];
% dmean=mean(data_test);
% dstd=std(data_test);
%
% x=[0.1,2.1,3.1]; %x轴数据
%
% y1=dmean; %y轴数据
%
% low1=dstd; %数据上限
% high1=dstd; %数据下限
%
% errorbar(x,y1,low1,high1,'-s','Color',color(1,:),'MarkerSize',10, 'MarkerEdgeColor',color(1,:),'MarkerFaceColor',[1,1,1],...
% 'LineWidth', 2,'CapSize',10)
% hold on
x=[0.1,2.1,3.1,4.1,5.1]; %x轴数据
y1=[1.1,0.7,0.75,0.9,0.95]; %y轴数据
low1=0.2*rand(1,length(y1)); %数据上限
high1=low1; %数据下限
y2=[1.3,0.32,0.35,0.3,0.25];
low2=0.1*rand(1,length(y2));
high2=low2;
y3=[1.5,1.2,1.15,1.6,1.2];
low3=0.3*rand(1,length(y3));
high3=low3;
% 画图
%调整整个图的范围
figure('Units', 'pixels', ...
'Position', [100 100 600 375]);
%'Color'整个连接线的颜色,'MarkerSize',标记的大小,'MarkerEdgeColor',标记边缘颜色,'MarkerFaceColor',标记填充颜色
%'LineWidth', 线宽,'CapSize',误差图标帽的大小
errorbar(x,y1,low1,high1,'-s','Color',color(1,:),'MarkerSize',10, 'MarkerEdgeColor',color(1,:),'MarkerFaceColor',[1,1,1],...
'LineWidth', 2,'CapSize',10)
hold on
errorbar(x,y2,low2,high2,'-o','Color',color(2,:),'MarkerSize',8, 'MarkerEdgeColor',color(2,:),'MarkerFaceColor',color(2,:),...
'LineWidth', 2,'CapSize',10)
hold on
errorbar(x,y3,low3,high3,'-^','Color',color(3,:),'MarkerSize',8, 'MarkerEdgeColor',color(3,:),'MarkerFaceColor',color(3,:),...
'LineWidth', 2,'CapSize',10)
hold on
ylabel('Mechanical Threshold')
% 调坐标的范围
ax = gca;
%x轴范围
ax.XTick = [0.1,2.1,3.1,4.1,5.1];
%x轴标签
ax.XTickLabels ={'Baseline', '0', '4h','24h','48h'};
ax.YTick= [1,2];
%y轴范围
ax.YLim=[0,2];
% 图例
% 不同图例不同颜色标记,'LineWidth',字体粗细,'FontSize',字体大小 ,'Orientation' 图例位置
% legend('第一次实验','第二次','第三次')
legend(['\color[rgb]{',num2str(color(1,:)) ,'}','Control'],['\color[rgb]{',num2str(color(2,:)) ,'}',' CFA'] ,...
['\color[rgb]{',num2str(color(3,:)) ,'}','BY'],'LineWidth',2,'FontSize',14,'Location','best');
legend('boxoff') %图例框消失
%设置字体
% set(gca,"FontSize",14,"LineWidth",2)
set(gca,"FontName","Times New Roman","FontSize",14,"LineWidth",2)
title("MY picture","FontName","Times New Roman","FontSize",14,"LineWidth",2);
box off
单个带误差棒得折线图
%% 单个误差带的折线图
data_test=[1,2,3,4,5;1.5,1.8,2.3,3.2,4.5;0.2,2.2,3.1,3.3,4.6];
dmean=mean(data_test);
dstd=std(data_test);
x=[0.1,2.1,3.1,4.1,5.1]; %x轴数据
y1=dmean; %y轴数据
low1=dmean-dstd; %数据上限
high1=dmean+dstd; %数据下限
figure('Position',[200,200,600,350])
color_set=[1.0000 0.6863 0.3490];
plot(x,y1,'-s','Color',color_set(1,:),'LineWidth',1.5)
hold on
h1=fill([x,fliplr(x)],[low1,fliplr(high1)],'r');
hold on
h1.FaceColor = color_set(1,:);%定义区间的填充颜色
h1.EdgeColor =[1,1,1];%边界颜色设置为白色
alpha (0.3) %设置透明色
scatter(x,data_test,20,'o','filled','MarkerFaceColor',[0.5,0.5,0.5],'MarkerEdgeColor',[0.5,0.5,0.5])
hold on
set(gca,'FontName','Times New Roman',"FontSize",12,"LineWidth",1.1)
% box off
legend('mean','std','data')
xlabel('x')
ylabel('y')
title('title')
立体饼图
%% 绘制饼图
load('color_cell1.mat')
mycolor1=color_cell1{1,1};
% data=[0.160784313725490 0.615686274509804 0.572549019607843 0.672549019607843 0.872549019607843];
data=[1,2,3,6,7];
figure
pie3(data,ones(1,length(data)))
colormap(mycolor1)
set(gca,'looseInset',[0 0 0 0]); %去除图片的白边
%%
figure
labels=["species1 48% ","species2 35% ","species3 17% "];
pie3([48,35,17],labels)
color1_set=[ 0.0039 0.4471 0.7373
0.4706 0.6706 0.1882
0.8471 0.3255 0.0980];
set(gca,'looseInset',[0 0 0 0]); %去除图片的白边
colormap(color1_set)
完整复现代码
另外O奖复现代码还包括:
- 柱状图
- 横向柱状图
- 分组柱状图
- 堆叠柱状图
- 三维柱状图
- 箱线图
- 热图
- 矩阵散点图
- 三维图
- 双轴图