当前位置: 首页 > article >正文

Matlab环形柱状图

数据准备:

名称    数值

Aa       21
Bb       23
Cc       35
Dd       47
保存为Excel文件后:

% Load data from Excel file
filename = 'data.xlsx';  % Ensure the file is in the current folder or provide full path
dataTable = readtable(filename);  % Read data from Excel file

% Assuming the first column contains names and second column contains values
Name = dataTable{:, 1};  % Data names from the first column
Data = dataTable{:, 2};  % Data values from the second column

% Number of data points
N = length(Data);

% Select a few colors from the "cool" colormap
coolColors = cool(N);  % Get N colors from the "cool" colormap

% Data range and ticks
YLim = [0, 50];
YTick = [];

% =========================================================================
% Start Plotting
if isempty(YLim) || isempty(YTick)
    tFig = figure('Visible', 'off');
    tAx = axes('Parent', tFig);
    tAx.NextPlot = 'add';
    bar(tAx, Data)
    if isempty(YLim), YLim = tAx.YLim; else, tAx.YLim = YLim; end
    if isempty(YTick), YTick = tAx.YTick; end
    close(tFig)
end

% Create a figure window
fig = figure('Units', 'normalized', 'Position', [0.2, 0.1, 0.5, 0.8]);
ax = axes('Parent', fig, 'Position', [0, 0, 1, 1]);
ax.NextPlot = 'add';
ax.XColor = 'none';
ax.YColor = 'none';
ax.DataAspectRatio = [1, 1, 1];

% Draw the coordinate axis and ticks
TLim = [pi/2, -pi - pi/6];
t01 = linspace(0, 1, 80);
tT = t01 .* diff(TLim) + TLim(1);
tX = cos(tT) .* (N + N / 2 + 1);
tY = sin(tT) .* (N + N / 2 + 1);
plot(ax, tX, tY, 'LineWidth', .8, 'Color', 'k');
ax.XLim = [-1, 1] .* (N + N / 2 + 2);
ax.YLim = [-1, 1] .* (N + N / 2 + 2);

tT = (YTick - YLim(1)) ./ diff(YLim) .* diff(TLim) + TLim(1);
tX = [cos(tT) .* (N + N / 2 + 1); cos(tT) .* (N + N / 2 + 1 + N / 50); tT .* nan];
tY = [sin(tT) .* (N + N / 2 + 1); sin(tT) .* (N + N / 2 + 1 + N / 50); tT .* nan];
plot(ax, tX(:), tY(:), 'LineWidth', .8, 'Color', 'k');

for i = 1:length(YTick)
    iT = tT(i);
    iR = iT / pi * 180;
    YTickHdl = text(ax, tX(2, i), tY(2, i), num2str(YTick(i)), 'FontName', 'Times New Roman', 'FontSize', 13, 'HorizontalAlignment', 'center');
    if mod(iR, 360) > 180 && mod(iR, 360) < 360
        YTickHdl.Rotation = iR + 90;
        YTickHdl.VerticalAlignment = 'top';
    else
        YTickHdl.Rotation = iR - 90;
        YTickHdl.VerticalAlignment = 'bottom';
    end
end

% Plot the bars with colors from the cool colormap
for i = 1:N
    tR = [(N + N / 2 + 1 - i - .4) .* ones(1, 80), (N + N / 2 + 1 - i + .4) .* ones(1, 80)];
    tT = t01 .* (Data(i) - YLim(1)) ./ diff(YLim) .* diff(TLim) + TLim(1);
    tX = cos([tT, tT(end:-1:1)]) .* tR;
    tY = sin([tT, tT(end:-1:1)]) .* tR;
    fill(ax, tX, tY, coolColors(i, :), 'LineWidth', 1, 'EdgeColor', 'k');
end

% Add data names
for i = 1:N
    text(ax, 0, N + N / 2 + 1 - i, [Name{i}, '  '], 'FontName', 'Times New Roman', 'FontSize', 16, 'HorizontalAlignment', 'right');
end


http://www.kler.cn/a/459555.html

相关文章:

  • ==和===的区别,被坑的一天
  • java class类对象 加载时机
  • PP模块部分BAPI函数
  • 活动预告 |【Part2】Microsoft 安全在线技术公开课:安全性、合规性和身份基础知识
  • C语言----指针数组
  • LinuxC高级day5
  • 【基础篇】一、MySQL数据库基础知识
  • 学习路之VScode--自定义按键写注释(插件)
  • 【开发心得】SpringBoot对接Stripe支付
  • 国产数据库TiDB从入门到放弃教程
  • python -【es】基本使用
  • 什么是自治系统和非自治系统
  • Android ActionBar 技术深度解析
  • 上海人工智能方案引领,CES Asia 2025共筑机器人未来
  • PHP语言的编程范式
  • HAL库STM32硬件IIC驱动数字电位器MCP4017
  • Linux(Centos 7.6)基础命令/常用命令说明
  • Python爬虫(二)- Requests 高级使用教程
  • 25 go语言(golang) - 内存分配机制原理
  • 鱼眼相机模型与去畸变实现
  • MySQL数据导出导出的三种办法(1316)
  • JAVA毕业设计205—基于Java+Springboot+vue3的民宿酒店管理系统(源代码+数据库)
  • 基于FPGA的RLC电阻电容电感测试仪设计(论文+源码)
  • XDMA IP
  • React 性能优化十大总结
  • springboot511基于SpringBoot视频点播系统的设计与实现(论文+源码)_kaic