All Projects → ahmedaq → Making-elegant-Matlab-figures

ahmedaq / Making-elegant-Matlab-figures

Licence: MIT license
A repository comprising multiple functions for making elegant publication-quality figures in MATLAB

Programming Languages

matlab
3953 projects

Projects that are alternatives of or similar to Making-elegant-Matlab-figures

Jekyll Theme Yat
🎨 Yet another theme for elegant writers with modern flat style and beautiful night/dark mode.
Stars: ✭ 113 (+156.82%)
Mutual labels:  beautiful, elegant
Musicx Music Player
Simple, Elegant ,Beautiful Material Android Music Player.
Stars: ✭ 179 (+306.82%)
Mutual labels:  beautiful, elegant
Startup Landing
Collection of free top of the line startup landing templates built using react/nextjs/gatsby. Free to download, simply edit and deploy! Updated weekly!
Stars: ✭ 176 (+300%)
Mutual labels:  beautiful
plume2
🚀a lightweight React state container for web and app
Stars: ✭ 74 (+68.18%)
Mutual labels:  elegant
sugar
Declarative HTTP client for Golang
Stars: ✭ 25 (-43.18%)
Mutual labels:  elegant
echarty
Minimal R/Shiny Interface to ECharts.js
Stars: ✭ 49 (+11.36%)
Mutual labels:  boxplot
pbft
Implementation of the Practical Byzantine Fault Tolerant Algorithm (pbft)
Stars: ✭ 114 (+159.09%)
Mutual labels:  beautiful
Boo
Boo - A beautiful, clean and responsive theme for Ghost.
Stars: ✭ 176 (+300%)
Mutual labels:  beautiful
Landmark Detection Robot Tracking SLAM-
Simultaneous Localization and Mapping(SLAM) also gives you a way to track the location of a robot in the world in real-time and identify the locations of landmarks such as buildings, trees, rocks, and other world features.
Stars: ✭ 14 (-68.18%)
Mutual labels:  probability-distribution
suru-plus-dark
Suru++ 25 Dark — A full dark cyberpunk, elegant, futuristic and Papirus-like third-party icons theme
Stars: ✭ 55 (+25%)
Mutual labels:  elegant
limus
🎨 Make your screenshot/image more professional by rotating, adding shadow and more.
Stars: ✭ 101 (+129.55%)
Mutual labels:  beautiful
flip view
A Flutter app with flip animation to view profiles of friends. 🌟
Stars: ✭ 69 (+56.82%)
Mutual labels:  beautiful
json-peek
Stringify JSON *just enough* to see what it is
Stars: ✭ 33 (-25%)
Mutual labels:  pretty
mathematics-statistics-for-data-science
Mathematical & Statistical topics to perform statistical analysis and tests; Linear Regression, Probability Theory, Monte Carlo Simulation, Statistical Sampling, Bootstrapping, Dimensionality reduction techniques (PCA, FA, CCA), Imputation techniques, Statistical Tests (Kolmogorov Smirnov), Robust Estimators (FastMCD) and more in Python and R.
Stars: ✭ 56 (+27.27%)
Mutual labels:  probability-distribution
Libheatmap
High performance C heatmap generation library. Supposed to be wrapped by higher-level languages.
Stars: ✭ 241 (+447.73%)
Mutual labels:  beautiful
PlotsOfData
Shiny App for comparison of samples
Stars: ✭ 47 (+6.82%)
Mutual labels:  boxplot
distfit
distfit is a python library for probability density fitting.
Stars: ✭ 250 (+468.18%)
Mutual labels:  probability-distribution
GapBot
Gap Messenger Api Bot Library for Python
Stars: ✭ 24 (-45.45%)
Mutual labels:  elegant
potato-dark
Dark and elegant blog theme for goHugo static site generator.
Stars: ✭ 21 (-52.27%)
Mutual labels:  elegant
awesome-conformal-prediction
A professionally curated list of awesome Conformal Prediction videos, tutorials, books, papers, PhD and MSc theses, articles and open-source libraries.
Stars: ✭ 998 (+2168.18%)
Mutual labels:  probability-distribution

Making Elegant Matlab Figures DOI

A repository comprising multiple functions for making elegant publication-quality figures in MATLAB.

alt text

 

Table of Contents

 

Boxplot

Generating boxplot in MATLAB using the default function boxplot.m is a bit cumbersome due to the large number of required (and somewhat strict in terms of format) inputs. Here, I have written a wrapper code for making nice boxplots quickly and efficiently.

Function: figure_boxplot.m

Example 1: Boxplot using only data input and no other specification
% Number of intended boxes in the figure
num_boxes = 8;          

% Generating random data
data = cell(1,num_boxes);   
for k = 1:num_boxes
    data{k} = randi(10) + randn(1,1000);
end

% Using the "figure_boxplot.m" function to plot the boxplot figure using the data

figure_boxplot(data)

alt text

Example 2: Boxplot using minimum input specifications
% Number of intended boxes in the figure
num_boxes = 6;          

% Generating random data
data = cell(1,num_boxes);   
for k = 1:num_boxes
    data{k} = randi(10) + randn(1,1000);
end

% Using the "figure_boxplot.m" function to plot the boxplot figure using the data, 
% x- and y-axis labels, and label of each box.
% For more information related to function inputs, check the function "figure_boxplot.m"

label_axes = {'Variable','Number'}; 
label_boxes = {'alpha','beta','gamma','delta','epsilon','zeta'};
figure_boxplot(data,label_axes,label_boxes);

alt text

Example 3: Boxplot using data input in matrix format

Instead of a cell, the code works even if the input is in matrix form of size num_samples x num_boxes.

% Number of intended boxes in the figure
num_boxes = 7;  
% Number of samples in each box plot
num_samples = 1000;

% Generating random data
data = zeros(num_samples,num_boxes);   
for k = 1:num_boxes
    data(:,k) = randi(10) + randn(num_samples,1);
end

% Using the "figure_boxplot.m" function to plot the boxplot figure using the data

figure_boxplot(data)

alt text

 

GeneratePDF

This is a code to generate nice (properly normalized) probability density function (PDF) plots with minimum amount of input arguments.

Function: generatePDF.m

Example 1: Generating PDF with only data input
% Generating random data
x = randn(1,500); 

figure;
generatePDF(x)

alt text

Example 2: Generating PDF in a specified color
% Loading colors
run colors_definitions.m

% Generating random data
x = randn(1,500); 

figure;
subplot(2,1,1)
generatePDF(x,'b') %You can use any color
title('Using one of the default colors')
subplot(2,1,2)
generatePDF(x,color_scheme_set1(1,:)) %You can use any color
title('Specifying a color manually')

alt text

Example 3: Generating PDFs in different styles
% Loading colors
run colors_definitions.m

% Generating random data
x = randn(1,5000); 

figure;
subplot(3,1,1)
generatePDF(x,color_scheme_set1(1,:),'hist') 
title('Histogram plot')
subplot(3,1,2)
generatePDF(x,color_scheme_set1(1,:),'curve') 
title('Curve plot')
subplot(3,1,3)
generatePDF(x,color_scheme_set1(1,:),'area') 
title('Area plot')

alt text

Example 4: Generating PDFs with specific number of bins
% Loading colors
run colors_definitions.m

% Generating random data
x = randn(1,5000); 

% Specifying the number of bins
no_of_bins = [20 30 50];

figure;
for k = 1:3
    subplot(3,1,k)
    generatePDF(x,color_scheme_set1(2,:),'hist',no_of_bins(k))
    title(sprintf('Bins = %d',no_of_bins(k)))
end

alt text

Example 5: Generating overlapping PDFs
% Loading colors
run colors_definitions.m

% Generating random data
x = randn(1,1e4); 
y = 2 + randn(1,1e4); 

figure;
generatePDF(x,color_scheme_set1(1,:),'area')
hold on
generatePDF(y,color_scheme_set1(2,:),'area')
legend('Data 1','Data 2'); legend boxoff

alt text

Example 6: Generating PDFs and saving figures
% Loading colors
run colors_definitions.m

% Generating random data
x = randn(1,1e4); 

% Specifying the number of bins
no_of_bins = 50;

% Data for saving figure in png format (4 inputs required)
savefig = 1; % 1 --> you want to save figure 
fig_name = 'generatePDF6';
fig_width_cm = 16; 
fig_height_cm = 10;

figure;
generatePDF(x,color_scheme_set1(3,:),'area',no_of_bins,...
    savefig,fig_name,fig_width_cm,fig_height_cm) 

alt text

Example 7: Generating overlapping PDFs with different color schemes
% Loading colors
run colors_definitions.m

% Generating random data
num_samples = 2e4;

x(1,:) = randn(1,num_samples); 
x(2,:) = 2 + 1.25 * randn(1,num_samples); 
x(3,:) = 4 + randn(1,num_samples); 
x(4,:) = 6 + 0.9 * randn(1,num_samples); 
x(5,:) = 8 + 1.5 * randn(1,num_samples); 
x(6,:) = 10 + 0.9 * randn(1,num_samples); 
x(7,:) = 13 + 1.1 * randn(1,num_samples); 
x(8,:) = 16 + 0.9 * randn(1,num_samples); 

% Color schemes to test
no_color_schemes = 5;
color_scheme{1} = color_scheme_npg;
color_scheme{2} = color_scheme_aaas;
color_scheme{3} = color_scheme_nejm;
color_scheme{4} = color_scheme_lancet;
color_scheme{5} = color_scheme_set1;

titles_schemes = {'NPG color scheme','AAAS color scheme',...
    'NEJM color scheme','LANCET color scheme','Set1 (Brewermap) color scheme'};

figure;
for m = 1:no_color_schemes
    subplot(no_color_schemes,1,m)
    for k = 1:8
        generatePDF(x(k,:),color_scheme{m}(k,:),'area')
        hold on
    end
    title(titles_schemes{m})
    legend('Data 1','Data 2','Data 3',...
        'Data 4','Data 5','Data 6',...
        'Data 7','Data 8','Location','NorthWest'); legend boxoff
end

alt text

 

Heatmap

Generating heatmap in MATLAB using the default function heatmap.m (introduced in version 2017a) is quite useful for visualizing the magnitude of elements in matrices. However, the size of the generated heatmaps requires a lot of tweaking to produce a reasonable figure. Here, I have written a wrapper code for making nice appropriate-sized heatmaps quickly and efficiently with minimum input.

Function: figure_heatmap.m

Example 1: Heatmap using only data input
% Generating data
x = randn(10,5);
C = corrcoef(x);

% Heatmap figure
figure_heatmap(C);

alt text

Example 2: Heatmap using a specific color scheme
%Using data of example 1

colorscheme = 'BuGn'; 
%Requires brewermap package
%Download from https://github.com/DrosteEffect/BrewerMap/blob/master/brewermap.m

% Heatmap figure
figure_heatmap(C,colorscheme);

alt text

Example 3: Heatmap with title and labels
%Using data of example 1

colorscheme = 'BuGn'; 
%Requires brewermap package
%Download from https://github.com/DrosteEffect/BrewerMap/blob/master/brewermap.m
text_title = 'Correlation Matrix';
text_labels = {'Variable','Variable'};

% Heatmap figure
figure_heatmap(C,colorscheme,text_title,text_labels);

alt text

Example 4: Heatmap with cell labels and limits of color scheme specified
%Using data of example 1

colorscheme = 'BuGn'; 
%Requires brewermap package
%Download from https://github.com/DrosteEffect/BrewerMap/blob/master/brewermap.m
text_title = 'Correlation Matrix';
text_labels = {'Variable','Variable'};
limits_data = [-1 1]; %for correlation matrix
text_labels_cells{1} = {'A','B','C','D','E'}; %x-axis cell labels
text_labels_cells{2} = {'A','B','C','D','E'}; %y-axis cell labels

% Heatmap figure
figure_heatmap(C,colorscheme,text_title,text_labels,limits_data,text_labels_cells);

alt text

Example 5: Heatmap of a rectangular matrix and automated saving of figure with approproate cell sizes
% Generating rectangular matrix data
X = randn(10,6);
colorscheme = 'YlGnBu';
%Requires brewermap package
%Download from https://github.com/DrosteEffect/BrewerMap/blob/master/brewermap.m
text_title = 'Tall Matrix';
text_labels = {'Variable 1','Variable 2'};
limits_data = [floor(min(X(:))) ceil(max(X(:)))];
text_labels_cells{1} = 1:size(X,2); %x-axis cell labels
text_labels_cells{2} = 1:size(X,1); %y-axis cell labels
savefig = 1;
savefig_name = 'heatmap_example5a';

% Heatmap figure
figure_heatmap(X,colorscheme,text_title,text_labels,limits_data,text_labels_cells,...
    savefig,savefig_name);

%
Y = randn(11,20);
colorscheme = 'BuPu';
%Requires brewermap package
%Download from https://github.com/DrosteEffect/BrewerMap/blob/master/brewermap.m
text_title = 'Fat Matrix';
text_labels = {'Variable 1','Variable 2'};
limits_data = [floor(min(X(:))) ceil(max(X(:)))];
text_labels_cells{1} = 1:size(Y,2); %x-axis cell labels
text_labels_cells{2} = 1:size(Y,1); %y-axis cell labels
savefig = 1;
savefig_name = 'heatmap_example5b';

% Heatmap figure
figure;
figure_heatmap(Y,colorscheme,text_title,text_labels,limits_data,text_labels_cells,...
    savefig,savefig_name);

alt text

alt text

Example 6: Heatmap of a big data matrix
% Generating rectangular matrix data
X = randn(15,50);
colorscheme = 'BuPu';
%Requires brewermap package
%Download from https://github.com/DrosteEffect/BrewerMap/blob/master/brewermap.m
text_title = 'Big Rectangular Matrix';
text_labels = {'Variable 1','Variable 2'};
limits_data = [floor(min(X(:))) ceil(max(X(:)))];
text_labels_cells{1} = 1:size(X,2); %x-axis cell labels
text_labels_cells{2} = 1:size(X,1); %y-axis cell labels
savefig = 1;
savefig_name = 'heatmap_example6';

% Heatmap figure
figure_heatmap(X,colorscheme,text_title,text_labels,limits_data,text_labels_cells,...
    savefig,savefig_name);

alt text

 

Violinplot

In progress ...

 

Citation

If you find this repo useful, please cite it using the following information:

Plain Text

Ahmed Abdul Quadeer. (2019, December 18). ahmedaq/Making-elegant-Matlab-figures: Release v1.0 (Version v1.0). Zenodo. http://doi.org/10.5281/zenodo.3582848

Bibtex

@software{ahmed_abdul_quadeer_2019_3582848, author = {Ahmed Abdul Quadeer}, title = {{ahmedaq/Making-elegant-Matlab-figures: Release v1.0}}, month = dec, year = 2019, publisher = {Zenodo}, version = {v1.0}, doi = {10.5281/zenodo.3582848}, url = {https://doi.org/10.5281/zenodo.3582848} }

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].