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

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; endif isempty(YTick), YTick = tAx.YTick; endclose(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) < 360YTickHdl.Rotation = iR + 90;YTickHdl.VerticalAlignment = 'top';elseYTickHdl.Rotation = iR - 90;YTickHdl.VerticalAlignment = 'bottom';end
end% Plot the bars with colors from the cool colormap
for i = 1:NtR = [(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:Ntext(ax, 0, N + N / 2 + 1 - i, [Name{i}, '  '], 'FontName', 'Times New Roman', 'FontSize', 16, 'HorizontalAlignment', 'right');
end

http://www.lryc.cn/news/510026.html

相关文章:

  • 【AI大模型】探索GPT模型的奥秘:引领自然语言处理的新纪元
  • 5.Python爬虫相关
  • Windows系统上配置eNSP环境的详细步骤
  • Database.NET——一款轻量级多数据库客户端工具
  • 新浪微博C++面试题及参考答案
  • 计算机视觉目标检测-1
  • 【物联网技术与应用】实验15:电位器传感器实验
  • java常用类(上)
  • 包管理工具npm、yarn、pnpm、cnpm详解
  • CI/CD是什么?
  • [Java]合理封装第三方工具包(附视频)
  • 常规配置、整合IDEA
  • 用Python写炸金花游戏
  • 计算机的错误计算(一百九十二)
  • 37 Opencv SIFT 特征检测
  • Nginx界的天花板-Oracle 中间件OHS 11g服务器环境搭建
  • 域名解析协议
  • 微信小程序给外面的view设置display:flex;后为什么无法给里面的view设置宽度
  • Maven怎么会出现一个dependency-reduced-pom.xml的文件
  • 突发!!!GitLab停止为中国大陆、港澳地区提供服务,60天内需迁移账号否则将被删除
  • 自学记录HarmonyOS Next DRM API 13:构建安全的数字内容保护系统
  • Vue 3 + Element Plus 实现文件上传组件:详细解析与实现指南
  • qt5.12.11+msvc编译器编译qoci驱动
  • Ubuntu 20.04 安装 LNMP
  • Llama 3 简介(一)
  • 在 CentOS 上安装 FFmpeg
  • Python------Pandas的数据结构
  • 矩阵碰一碰发视频源码技术解析,支持OEM
  • 【汇编语言】外中断(一)—— 外中断的魔法:PC机键盘如何触发计算机响应
  • pymssql-2.1.4.dev5-cp37-cp37m-win_amd64.whl 安装