# Bar Chart Race Plot
[![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=minoue-xx/BarChartRaceAnimation)
[![View BarChartRaceAnimation on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://jp.mathworks.com/matlabcentral/fileexchange/75167-barchartraceanimation)
Copyright (c) 2020 Michio Inoue
This repository provides a function that generates a bar chart race plot.
### Requirements: R2019b
![image_0.png](README_images/image_0.png)
# Syntax
`barChartRace(X)` draws the animation of the bar chart for each rows of `X`. `X` can be numeric array, table, or timetable.
`h1 = barChartRace(X)` returns a handle (`h1`) to the figure with bar chart.
`[h1,h2] = barChartRace(X)` returns a handle (`h2`) to the figure with the data description in addition to `h1`.
`[ __ ] = barChartRace(X, Name, Value)` to use some Name-Value Pair Arguments.
# Name-Value Pair Arguments
**'Time':** A vector (numeric or datetime) that represents the time for each raw of `X`. The default is `1:size(inputs,1)`
**'LabelNames':** A cell or string vector of the variable names, each element corresponds to each columns of `X`. The default is `"name" + string(1:size(X,2))` if `X` is a numeric array or the name of varialbes if `X` is a table or timetable.
**'ColorGroups':** A cell or string vector of color group name. Each element corresponds to each columns of `X`. The default is `"name" + string(1:size(X,2))` if `X` is a numeric array or the name of varialbes if `X` is a table or timetable. Example: With `'ColorGroups' = ['g1','g1','g2','g1','g2']`, the bars of 1st, 2nd, 4th column of inputs will the same color. The default color order will be used.
**'NumDisplay':** A number of variable to display from the top. The default is all, `size(X,2)`.
**'NumInterp':** A number of datapoints to be generated between each time stamp of `X`. The larger the value is the smoother/slower the transtion. The default is 2.
**'Method':** A method for above interpolation. The default is 'linear', but can be 'spline' for more dynamic bar transition.
**'GenerateGIF':** If TRUE, GIF animation of bar chart race will be generated.
**'Outputfilename':** Output GIF file name
**'XlabelName':** The XLabelName, the defaultis "" (emtpy)
**'IsInteger':** If TRUE, the text shown next to each bar will be arounded to interger value. The default is TRUE.
**'FontSize':** Axes fontsize, the default is 15.
**'DisplayFontSize':** The fontsize of the time stamp display, the default is 15.
**'YTickLabelRotation':** The angle of the y-axes label text, the default is 0.
**'Position':** Location and size of the drawable area, specified as a vector of the form [left bottom width height]. The deafult is 'DefaultFigurePosition'
**'GIFDelayTime':** Delay before displaying next image. Delay before displaying next image, in seconds, a scalar value in the range [0,655]. The default here is 0.05 (see imwrite for details)
**'Footnote':** String text to display at the bottom right corner of the axes. For multiple lines of text, use a vector of strings. Default is "visualized by MATLAB"
# Example
See `barChartRace.m` for the detail options.
Here's a toy data set and its transition of rankings. The variable A starts from 5th place and move to 1st place in the end.
```matlab
addpath("function");
% Some toy (time series) data set
maxT = 45;
time = 0:50;
x0 = 1:5; % initial data
rate = (5:-1:1)/100*2; % growth rate
data = zeros(length(time),length(x0));
data(1,:) = x0;
for ii=2:length(time)
data(ii,:) = data(ii-1,:).*(1+rate);
end
[h1, h2] = barChartRace(data);
```
![figure_0.png](README_images/figure_0.png)
![figure_1.png](README_images/figure_1.png)
```matlab
% The gif at the top will be generated by the following setting
names = ["A","B","C","D","E"];
barChartRace(data,"IsInteger",false,"LabelNames",names,"GenerateGIF",true);
```
![figure_2.png](README_images/figure_2.png)
# Scripts
There are also some sample scripts which will generate a bar chart race plot. These can be a good example to work through the basic ideas behind the bar chart race animation with graphics object of MATLAB. These script can work with the earlier version of MATLAB.
- `barChartRace_UniColor.m`: Single color version
- `barChartRace_multiColor_oneBar.m`: Multi-color version with one bar object.
- `barChartRace_multiColor_multiBar.m`: Multi0color version with multi-bar objects (for users with R2017a or earlier.)
Note: The implementation of a function `barChartRace` is similar to that of `barChartRace_multiColor_oneBar.m` but many additional options.
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
Matlab科研辅导帮
- 粉丝: 3w+
- 资源: 7819
最新资源
- Golang_Puzzlers-春节主题资源
- AndBase-javaEE框架项目资源
- 智慧园区管理系统-活动资源
- XLang-汇编语言资源
- 基于数据预处理与PSO-SVM优化的风功率预测及其聚类分析-一种提高预测准确性的方法,基于数据预处理与PSO-SVM优化的风功率预测及聚类分析-一种提高可再生能源预测准确性的方法,基于数据预处理和
- 风光储系统并网Simulink仿真建模深度分析:从原理到实践的应用研究,风光储系统并网技术:基于Simulink仿真建模的深度分析与研究,风光储系统并网simulink仿真建模分析 ,风光储系统; 并
- 基于自抗扰控制的幅频特性曲线研究:传函推导与PID等效在跟踪和抗扰曲线上的应用分析,基于自抗扰控制的幅频特性曲线研究:PID等效性及其在跟踪和抗扰曲线上的应用分析,自抗扰控制,幅频特性曲线,传函推导
- 小程序商城源码-Java-C语言资源
- 基于FPGA的高效OFDM调制解调技术实现,Verilog代码编写及FFT与IFFT的双重验证:包括详细的testbench操作流程及程序录像,基于FPGA的OFDM调制解调Verilog实现:包含I
- 基于FPGA的256点FFT算法Verilog实现与程序操作指南,包含Testbench及无IP核应用案例的演示录像,基于FPGA实现的256点FFT傅里叶变换算法与Verilog代码优化方案含测试与
- 基于两阶段鲁棒优化的微电网经济调度策略:应对分布式电源与负荷不确定性的高效调度方案,基于分布式电源与负荷不确定性的微电网两阶段鲁棒优化经济调度策略,微电网两阶段鲁棒优化经济调度方法 参考文献:微电网两
- 通过场分布分析光子晶体的色散特性研究,光子晶体色散研究:场分布与光子能量关系解析,通过场分布得到光子晶体的色散 ,场分布; 光子晶体; 色散,光子晶体色散分析:场分布的揭示与应用
- 小程序商城源码-Java-C++资源
- IOTGate-Java资源
- Aestate-Python资源
- nats.swift-Swift资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)