PlotPub!一款讓你欲罷不能的科研繪圖工具箱
- 2019 年 10 月 29 日
- 筆記
PlotPub是K. M. Masum Habib開發的一款高品質繪圖工具箱,作者將繪圖相關的設置全部封裝在了一個名為「Plot」的類中,只需要簡單的設置即可繪製一幅漂亮的影像。該工具箱支援EPS, PDF, PNG, JPEG,TIFF和SVG等格式文件的輸出,接下來就一起來看看作者的漂亮示例吧:
示例一、多曲線製圖
% Multiple plots using plotPub clear all; % 將庫文件添加到matlab搜索路徑中 addpath('../lib'); %% lets plot 3 cycles of 50Hz AC voltage f = 50; Vm = 10; phi = pi/4; % generate the signal t = [0:0.0001:3/f]; th = 2*pi*f*t; v1 = Vm*sin(th); v2 = Vm*sin(th - phi); v3 = Vm*sin(th - phi*2); %% plot and settings plt = Plot(t*1E3, v1, t*1E3, v2, t*1E3, v3); % 坐標軸設置 plt.XLabel = 'Time, t (ms)'; % xlabel plt.YLabel = 'Voltage, V (V)'; %ylabel plt.YTick = [-10, 0, 10]; plt.YLim = [-11, 11]; % 保存繪製影像 plt.export('plotMultiple.png');
示例二、多曲線多標記製圖
clear all; % load previously generated fig file figFile = 'multiple.fig'; plt = Plot(figFile); % change properties plt.XLabel = 'Time, t (ms)'; % xlabel plt.YLabel = 'Voltage, V (V)'; %ylabel plt.YTick = [-10, 0, 10]; %[tick1, tick2, .. ] plt.XLim = [0, 80]; % [min, max] plt.YLim = [-11, 11]; % [min, max] plt.Colors = { % three colors for three data set [ 1, 0, 0] [ 0.25, 0.25, 0.25] [ 0, 0, 1] }; plt.LineWidth = [2, 2, 2]; % three line widths plt.LineStyle = {'-', '-', '-'}; % three line styles plt.Markers = {'o', '', 's'}; plt.MarkerSpacing = [15, 15, 15]; plt.Legend = {'theta = 0^o', 'theta = 45^o', 'theta = 90^o'}; % legends % Save? comment the following line if you do not want to save plt.export('plotMarkers.png');
示例三、雙對數坐標製圖
% Log-log scale. clear all; addpath('../lib'); %% lets plot 3 cycles of 50Hz AC voltage f = 50; Vm = 10; phi = 0; % generate the signal t = [0:0.00001:3/f]; th = 2*pi*f*t; v = Vm*sin(th+phi); vsqr = v.^2; %% plot and settings plt = Plot(t*1E3, vsqr); plt.XLabel = 'Time, t (ms)'; % xlabel plt.YLabel = 'Voltage, V (V)'; %ylabel plt.YScale = 'log'; % 'linear' or 'log' plt.XScale = 'log'; % 'linear' or 'log' plt.YLim = [1E-3, 1E3]; % [min, max] plt.YTick = [1E-3, 1E-1, 1E1, 1E3]; %[tick1, tick2, .. ] plt.YGrid = 'on'; % 'on' or 'off' plt.XGrid = 'on'; % 'on' or 'off' % 保存影像 plt.export('plotSimpleLogLog.png');