当前位置:   article > 正文

MATLAB 绘图之科技论文常用的数据可视化_matlab绘图线条颜色论文

matlab绘图线条颜色论文

MATLAB 绘图之科技论文常用的数据可视化

单柱状图

代码:

%%
clc; clear all; close all;
%%
x = [61.42 50.89 1.25 4.89];
b = bar(x,0.27,'b')
for i = 1:length(x)
    text(i-0.12, x(i)+2.0, num2str(x(i)))
end
ch = get(b, 'children')
set(gca, 'XTickLabel',{'N = 0', 'N = 1', 'N = 2', 'N = 3'})
xlabel('polynomial order')
ylabel('mape_{test} (%)')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

输出:

组柱状图

代码:

clc; clear all; close all
%%
train = [0.8646     0.8784  0.8626 
         0.6135     0.5728  0.5528 ]';
test = [1.5566  1.2035  1.2163 
        2.3511  1.3273  1.3609]';
%% Figure 2
figure (2)
subplot(121)
bar(train,'grouped') % 将train按照列分组 为 2 组
xlabel('Models','FontName', 'Times New Roman','FontSize', 9)
ylabel('Errors (%)','FontName', 'Times New Roman','FontSize', 9)
ylim([0 1.2])
legend('MAPE','RMSPE') 
set(gca, 'FontName', 'Times New Roman','FontSize', 9, ...
    'XTickLabel',{'OGMP_F(1,1,0)', 'OGMP_L(1,1,0)', 'OGMP_M(1,1,0)'})

subplot(122)
bar(test,'grouped')
xlabel('Models','FontName', 'Times New Roman','FontSize', 9)
ylabel('Errors (%)','FontName', 'Times New Roman','FontSize', 9)
ylim([0 2.5])
legend('MAPE','RMSPE') 
set(gca, 'FontName', 'Times New Roman','FontSize', 9, ...
    'XTickLabel',{'OGMP_F(1,1,0)', 'OGMP_L(1,1,0)', 'OGMP_M(1,1,0)'})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

输出:

两个纵坐标轴

数据局部预览:

0.000.00-0.0610.2862.18
0.000.01-0.0610.2662.16
0.000.02-0.0610.2362.15
0.000.03-0.0610.2162.13
0.000.04-0.0610.1862.11
0.000.05-0.0610.1662.10
0.000.06-0.0610.1362.08
0.000.07-0.0610.1162.06
0.000.08-0.0610.0862.05
polyOrderbaCoedevCoemapeTrainmapeTest

代码:

gmpb = xlsread('GMPB_0.csv');
bc = gmpb(:,2); % X轴对应的数值
[haxes, hline1, hline2] = plotyy(bc, gmpb(:,4), bc, gmpb(:,5)); % gmpb(:,4) 左Y对应的数值, gmpb(:,5) 右Y对应的数值
grid on
xlabel('background coefficient'); ylabel('MAPE_{train} (%)')
axes(haxes(1)); set(hline1,'LineStyle','-','LineWidth',2); 
axes(haxes(2)); set(hline2,'LineStyle','--','LineWidth',2)
title('\it{N} \rm{= 0}');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

输出:

数据划分与标注

数据局部预览:

20001066.91068.31040.21066.91066.91055.6
20011157.61149.71228.31147.21195.21158.7
20021286.01292.61365.71315.71357.81304.8
20031477.11484.71518.41496.41525.21485.8
20041695.21700.41688.21690.11703.91694.2
20051913.01927.61877.11897.81897.31922.0
20062180.62160.22087.02120.52108.22161.5
YearConsumptionGMPB(1,1,2)GMP(1,1,0)NDGM(1,1)VerhulstCPR

代码:

clc; clear all; close all;
%%
[gmp,txt,raw] = xlsread('对比模型结果.xlsx');
t = gmp(:,1);
%%
figure (4)
plot(t, gmp(:,2),'+k','LineWidth',2); hold on
plot(t, gmp(:,3),'-rs','LineWidth',1); 
plot(t, gmp(:,4),'-gv','LineWidth',1);
plot(t, gmp(:,5),'-bo','LineWidth',1); 
plot(t, gmp(:,6),'-c<','LineWidth',1); 
plot(t, gmp(:,7),'-m>','LineWidth',1); 
legend('Actual values', 'GMPB(1,1,2)', 'GMP(1,1,0)', 'NDGM(1,1)', 'Verhulst', 'CPR')
plot([2010.5 2010.5], [1000 6000], 'k--')
text(2005, 5000, 'Sequence for buliding models \leftarrow ')
% text(2010, 5000, '\rightarrow Testing sequence')
xlabel('Year')
ylabel('Fitted and predicted values of ApCEC (kilowatt hour)')
hold off
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

输出:

数学公式的表述

示例代码:

xlabel('$$k$$','interpreter', 'latex', 'FontName', 'Cambria', 'FontSize', 12)
ylabel('$$\delta^{(r)}(k)$$','interpreter', 'latex', 'FontName', 'Cambria', 'FontSize', 12)
  • 1
  • 2

指定标注形状及颜色

代码:

t = 1990:2014;
cvc = [95384 100413 105602 111490 118071 123471 129665 130082 ...
    130260 135132 140993 148264 161935 189269 220738 250835 ...
    275134 299271 306455 321336 343601 370163 381515 394794 400299];
plot(t, cvc, '-bo', 'Linewidth', 1.5, ...
    'MarkerEdgeColor',[.5 .5 .5], 'MarkerFaceColor',[.5 .5 .5], 'MarkerSize',5)
hold on
plot(2005.5*[1 1], 5*10^5*[0 1], ':r', 'Linewidth', 1)
text(2000, 4*10^5, 'training set \leftarrow ') % training set
plot(2009.5*[1 1], 5*10^5*[0 1], ':r', 'Linewidth', 1)
text(2010, 3*10^5, '\rightarrow test set') % test set
textstr={'validation'; '   set'}; % validation set
text(2006, 1.5*10^5, textstr) 
% text(2005.8, 1.5*10^5, '\rightarrow') % validation set
% text(2008.5, 1*10^5, '\leftarrow') % validation set
hold off
xlim([1989 2016])
xlabel('Year'); ylabel('annual total energy consumption (10^4 tce)')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

输出:

图形局部放大

数据局部预览:

0.0258.9841153607.07
0.0418.2369914261.72
0.0611.375056999.15
0.089.8094824481.429
0.110.013443338.315
0.1211.109052736.983
0.1412.792612391.725
0.1614.937032183.315
0.1817.482022055.052
rhocondnum_0condnum_1

代码:

clc; clear all; close all
%% 
condnum = xlsread('condnum.csv');
rho = condnum(:,1); condnum_0 = condnum(:,2); condnum_1 = condnum(:,3);
%% 绘图
figure (1)
% 
subplot(121)
plot(rho, condnum_0, '-bo', 'LineWidth',1.5, ...
    'MarkerEdgeColor',[.5 .5 .5], 'MarkerFaceColor',[.5 .5 .5], 'MarkerSize',5)
xlabel('multiple coefficient'); ylabel('condition number')
axes('position', [0.17 0.58, 0.20, 0.30])
plot(rho, condnum_0, '-bo', 'LineWidth',1.5, ...
    'MarkerEdgeColor',[.5 .5 .5], 'MarkerFaceColor',[.5 .5 .5], 'MarkerSize',5); grid on; xlim([0.04 0.44])
% 
subplot(122)
plot(rho, condnum_1, '-bo', 'LineWidth',1.5, ...
    'MarkerEdgeColor',[.5 .5 .5], 'MarkerFaceColor',[.5 .5 .5], 'MarkerSize',5)
xlabel('multiple coefficient'); ylabel('condition number')
axes('position', [0.67 0.58, 0.20, 0.30])
plot(rho, condnum_1, '-bo', 'LineWidth',1.5, ...
    'MarkerEdgeColor',[.5 .5 .5], 'MarkerFaceColor',[.5 .5 .5], 'MarkerSize',5); grid on; xlim([0.04 0.44])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

输出:

多种线指定颜色

数据局预览:

WS1WS2WS3WS4WS5WS6WS7WS8WS9WS10WS11WS12WS13WS14WS15WS16WS17WS18WS19WS20WS21WS22WS23WS24WS25WS26WS27
6.50767.80227.78347.04557.31996.91446.82696.86707.90917.16546.57406.11917.05597.27186.24317.13057.73436.37807.57967.64007.39057.52888.23107.62886.87087.27607.2873
6.51557.81437.78596.99287.27586.89486.88266.88827.98307.25776.52036.11607.18737.31626.27387.22427.68616.37707.57207.60937.44057.51388.18407.62336.91317.27887.2710
6.49827.75067.74326.92827.26796.91436.84576.90248.00377.24446.56976.07547.17067.30106.20637.21027.66656.28267.57577.63487.44457.47428.13697.56656.92457.27977.2716
6.49437.76287.75786.96017.25067.00646.87266.89237.99487.21656.55436.06977.17947.28896.21307.18727.69896.27747.56947.64667.44837.42948.11527.54296.92207.28747.2611
6.50877.76497.77136.98147.28736.96486.86116.88737.99847.23086.58136.07817.20377.27316.22217.19587.72966.28377.57007.65107.52407.42288.11087.54966.93027.26617.2566
6.50947.75837.76676.97617.28506.96206.83646.87018.00177.23166.60126.09717.22247.28256.21357.20957.72896.27937.56557.67587.53857.41418.10637.52266.93897.26037.2147
6.51187.75337.76606.97847.29116.94376.84036.86518.00177.22916.59396.08497.22987.28676.21917.22317.71696.27977.54307.68017.52757.42408.10947.54676.95807.26847.2202
6.52347.75027.76356.96417.29646.94126.82876.87437.99387.21366.58836.07487.21337.28776.24507.23677.71026.27327.54297.67077.53837.41908.11047.55626.95457.27047.2258

代码:

clear all; close all; clc
%% 
X = xlsread('5000iterationsCumsmeanMeasure.xlsx');
X = X(1:2000,:);
[m, n] = size(X);
t = (1:m)';
%%
figure (1)
C = linspecer(n);
for i=1:n
    plot(X(:,i), 'color', C(i,:), 'linewidth', 2); 
    hold on
end
xlim([-100 2000])
xlabel('Iterations ', 'FontName', 'Times New Roman', 'FontSize', 12)
ylabel('Comprehensive value', 'FontName', 'Times New Roman', 'FontSize', 12)
set(gca, 'FontName', 'Times New Roman', 'FontSize', 12)
hleg = legend('WS 01','WS 02','WS 03', 'WS 04','WS 05','WS 06','WS 07','WS 08','WS 09','WS 10',...
            'WS 11','WS 12','WS 13', 'WS 14','WS 15','WS 16','WS 17','WS 18','WS 19','WS 20',...
            'WS 21','WS 22','WS 23', 'WS 24','WS 25','WS 26','WS 27', 'FontSize', 8, 'Location','EastOutside') % 
hold off
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

输出:

特别注意: 在当前工作目录下添加 ‘function’ 文件(linspecer.m)

% function lineStyles = linspecer(N)
% This function creates an Nx3 array of N [R B G] colors
% These can be used to plot lots of lines with distinguishable and nice
% looking colors.
% 
% lineStyles = linspecer(N);  makes N colors for you to use: lineStyles(ii,:)
% 
% colormap(linspecer); set your colormap to have easily distinguishable 
%                      colors and a pleasing aesthetic
% 
% lineStyles = linspecer(N,'qualitative'); forces the colors to all be distinguishable (up to 12)
% lineStyles = linspecer(N,'sequential'); forces the colors to vary along a spectrum 
% 
% % Examples demonstrating the colors.
% 
% LINE COLORS
% N=6;
% X = linspace(0,pi*3,1000); 
% Y = bsxfun(@(x,n)sin(x+2*n*pi/N), X.', 1:N); 
% C = linspecer(N);
% axes('NextPlot','replacechildren', 'ColorOrder',C);
% plot(X,Y,'linewidth',5)
% ylim([-1.1 1.1]);
% 
% SIMPLER LINE COLOR EXAMPLE
% N = 6; X = linspace(0,pi*3,1000);
% C = linspecer(N)
% hold off;
% for ii=1:N
%     Y = sin(X+2*ii*pi/N);
%     plot(X,Y,'color',C(ii,:),'linewidth',3);
%     hold on;
% end
% 
% COLORMAP EXAMPLE
% A = rand(15);
% figure; imagesc(A); % default colormap
% figure; imagesc(A); colormap(linspecer); % linspecer colormap
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% by Jonathan Lansey, March 2009-2013 �Lansey at gmail.com               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 
%% credits and where the function came from
% The colors are largely taken from:
% http://colorbrewer2.org and Cynthia Brewer, Mark Harrower and The Pennsylvania State University
% 
% 
% She studied this from a phsychometric perspective and crafted the colors
% beautifully.
% 
% I made choices from the many there to decide the nicest once for plotting
% lines in Matlab. I also made a small change to one of the colors I
% thought was a bit too bright. In addition some interpolation is going on
% for the sequential line styles.
% 
% 
%%

function lineStyles=linspecer(N,varargin)

if nargin==0 % return a colormap
    lineStyles = linspecer(64);
%     temp = [temp{:}];
%     lineStyles = reshape(temp,3,255)';
    return;
end

if N<=0 % its empty, nothing else to do here
    lineStyles=[];
    return;
end

% interperet varagin
qualFlag = 0;

if ~isempty(varargin)>0 % you set a parameter?
    switch lower(varargin{1})
        case {'qualitative','qua'}
            if N>12 % go home, you just can't get this.
                warning('qualitiative is not possible for greater than 12 items, please reconsider');
            else
                if N>9
                    warning(['Default may be nicer for ' num2str(N) ' for clearer colors use: whitebg(''black''); ']);
                end
            end
            qualFlag = 1;
        case {'sequential','seq'}
            lineStyles = colorm(N);
            return;
        otherwise
            warning(['parameter ''' varargin{1} ''' not recognized']);
    end
end      

% predefine some colormaps
  set3 = colorBrew2mat({[141, 211, 199];[ 255, 237, 111];[ 190, 186, 218];[ 251, 128, 114];[ 128, 177, 211];[ 253, 180, 98];[ 179, 222, 105];[ 188, 128, 189];[ 217, 217, 217];[ 204, 235, 197];[ 252, 205, 229];[ 255, 255, 179]}');
set1JL = brighten(colorBrew2mat({[228, 26, 28];[ 55, 126, 184];[ 77, 175, 74];[ 255, 127, 0];[ 255, 237, 111]*.95;[ 166, 86, 40];[ 247, 129, 191];[ 153, 153, 153];[ 152, 78, 163]}'));
set1 = brighten(colorBrew2mat({[ 55, 126, 184]*.95;[228, 26, 28];[ 77, 175, 74];[ 255, 127, 0];[ 152, 78, 163]}),.8);

set3 = dim(set3,.93);

switch N
    case 1
        lineStyles = { [  55, 126, 184]/255};
    case {2, 3, 4, 5 }
        lineStyles = set1(1:N);
    case {6 , 7, 8, 9}
        lineStyles = set1JL(1:N)';
    case {10, 11, 12}
        if qualFlag % force qualitative graphs
            lineStyles = set3(1:N)';
        else % 10 is a good number to start with the sequential ones.
            lineStyles = cmap2linspecer(colorm(N));
        end
otherwise % any old case where I need a quick job done.
    lineStyles = cmap2linspecer(colorm(N));
end
lineStyles = cell2mat(lineStyles);
end

% extra functions
function varIn = colorBrew2mat(varIn)
for ii=1:length(varIn) % just divide by 255
    varIn{ii}=varIn{ii}/255;
end        
end

function varIn = brighten(varIn,varargin) % increase the brightness

if isempty(varargin),
    frac = .9; 
else
    frac = varargin{1}; 
end

for ii=1:length(varIn)
    varIn{ii}=varIn{ii}*frac+(1-frac);
end        
end

function varIn = dim(varIn,f)
    for ii=1:length(varIn)
        varIn{ii} = f*varIn{ii};
    end
end

function vOut = cmap2linspecer(vIn) % changes the format from a double array to a cell array with the right format
vOut = cell(size(vIn,1),1);
for ii=1:size(vIn,1)
    vOut{ii} = vIn(ii,:);
end
end
%%
% colorm returns a colormap which is really good for creating informative
% heatmap style figures.
% No particular color stands out and it doesn't do too badly for colorblind people either.
% It works by interpolating the data from the
% 'spectral' setting on http://colorbrewer2.org/ set to 11 colors
% It is modified a little to make the brightest yellow a little less bright.
function cmap = colorm(varargin)
n = 100;
if ~isempty(varargin)
    n = varargin{1};
end

if n==1
    cmap =  [0.2005    0.5593    0.7380];
    return;
end
if n==2
     cmap =  [0.2005    0.5593    0.7380;
              0.9684    0.4799    0.2723];
          return;
end

frac=.95; % Slight modification from colorbrewer here to make the yellows in the center just a bit darker
cmapp = [158, 1, 66; 213, 62, 79; 244, 109, 67; 253, 174, 97; 254, 224, 139; 255*frac, 255*frac, 191*frac; 230, 245, 152; 171, 221, 164; 102, 194, 165; 50, 136, 189; 94, 79, 162];
x = linspace(1,n,size(cmapp,1));
xi = 1:n;
cmap = zeros(n,3);
for ii=1:3
    cmap(:,ii) = pchip(x,cmapp(:,ii),xi);
end
cmap = flipud(cmap/255);
end
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/798969
推荐阅读
相关标签
  

闽ICP备14008679号