MATLAB | 情人节画个花瓣venn图?

2024-02-13 22:20

本文主要是介绍MATLAB | 情人节画个花瓣venn图?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前七夕节情人节各种花,相册,爱心啥的都快画够了,今年画个花瓣韦恩图?


花瓣上的数字是仅属于该类的样本数,而中心的数字是属于每一类的样本数


教程部分

0 数据准备

% 给组起名t1 t2 t3...t15
setName = compose('t%d', 1:15);% 随机生成数据
Data = [rand(200, 15) > .1; rand(200, 15) > .85];% 设置字体
numFont = {'FontSize', 14, 'FontName', 'Times New Roman'};
labFont = {'FontSize', 16, 'FontName', 'Times New Roman'};

其中Data数据是个0-1矩阵,矩阵每一行代表一个样本,如果第n列是1代表该样本属于第n类,是0则代表不属于。


1 配色

CList = lines(15);
% C = flowerPlotColor();
% CList = C.CList631;

这里直接取MATLAB自带的lines配色,当然我也准备了很多其他配色,可以复制下来用:

function C=flowerPlotColor
C.CList1877 = [0.2431    0.3294    0.58820.5098    0.5647    0.73330    0.5569    0.80780.3490    0.7804    0.92160.0275    0.4431    0.52940.4157    0.6667    0.71760.0392    0.5647    0.52550.3294    0.7490    0.71760.5569    0.1255    0.26270.7373    0.4784    0.56080.8784    0.3765    0.49410.9255    0.6275    0.69800.9961    0.6275    0.56470.9961    0.8118    0.78040.7216    0.7373    0.75690.8824    0.8863    0.8980];
C.CList1514 = [0.4078    0.5647    0.81570.9098    0.7843    0.65880.9725    0.8784    0.72160.9725    0.9725    0.97250.2196    0.3137    0.43920.5333    0.6588    0.97250         0         00.5961    0.5961    0.69020.3451    0.4706    0.56470.8471    0.8471    0.97250.7216    0.7216    0.81570.8157    0.6902    0.56470.7216    0.5961    0.47060.2510    0.4078    0.62750.7216    0.7843    0.9725];
C.CList1596 = [0.2549    0.5490    0.94120.9882    0.7059    0.25490.8784    0.2510    0.03920.0196    0.3922    0.57250.7490    0.7490    0.74900.1020    0.2314    0.41181.0000    0.8902    0.50980.0706    0.6118    0.86670.7922    0.4196    0.29410    0.3608    0.85880.9529    0.8235    0.53330.3137    0.3882    0.50590.9451    0.7255    0.65880.8784    0.5137    0.03920.4706    0.5765    0.7451];
C.CList1470 = [0.1882    0.4078    0.59610.2824    0.5020    0.69020.9098    0.8157    0.62750.7843    0.6902    0.50200.3765    0.5961    0.78430.1255    0.1882    0.28240         0         00.4078    0.3765    0.28240.5961    0.5333    0.37650.5647    0.7529    0.90980.2196    0.3137    0.47060.6902    0.7216    0.75290.9725    0.9725    0.97250.5020    0.5333    0.59610.9725    0.9098    0.7843];
C.CList1827 = [1.0000    0.6118         00.9686    0.7412    0.35291.0000    0.8000    0.60001.0000    1.0000    0.20001.0000    1.0000    0.61180.8039    0.3882    0.38820.8000    0.6000    0.80001.0000    0.6196    0.38820.3922    0.4275    0.80000.6118    0.6118    1.00000.2000    0.6000    1.00000.6000    0.8000    1.00001.0000    1.0000    0.80000.6941    0.5843    0.47840.9294    0.5333    0.29800.9608    0.9294         00.8667    1.0000    1.0000];
C.CList1607 = [0.8863    0.5686    0.56860.6000    0.8667    0.57250.5765    0.8471    0.72550.5804    0.7686    0.82750.5804    0.6039    0.80780.7020    0.5804    0.80000.8000    0.5882    0.69410.8000    0.6431    0.60000.8745    0.8980    0.57251.0000    0.6471    0.37650.4196    1.0000    0.38820.3961    1.0000    0.80000.3961    0.7686    1.00000.3961    0.4196    1.00000.6784    0.3961    1.00001.0000    0.3961    0.95691.0000    0.3961    0.51761.0000    0.3961    0.3961];
C.CList631 = [0.1059    0.6392    0.77650.1725    0.7098    0.75290.1882    0.7373    0.67840.1294    0.6902    0.52940.2000    0.6510    0.36080.3412    0.6392    0.21570.6353    0.7137    0.15290.8353    0.7333    0.12940.9725    0.7137    0.12550.9725    0.5725    0.09020.9412    0.4039    0.09800.8784    0.2039    0.14900.9647    0.2863    0.44310.9882    0.4431    0.61960.9216    0.4510    0.70200.8078    0.4118    0.74510.6353    0.4275    0.76080.4706    0.4510    0.75290.3098    0.4863    0.7294];
end




2 数据处理及图窗生成

% 数据计算
cT = linspace(0, 2*pi, 200);
cX = cos(cT).*8 + 8;
cY = sin(cT).*3;
cXY = [cX;cY];
setNum = size(Data, 2);
rT = 2*pi./setNum;
rM = [cos(rT),-sin(rT); sin(rT),cos(rT)];uniq = sum(Data.*(sum(Data,2) == 1),1);
core = sum(sum(Data,2) == setNum);figure('Units', 'normalized', 'Position', [.1,.1,.5,.8]);
ax=gca;
ax.NextPlot = 'add';
ax.DataAspectRatio = [1,1,1];
ax.XColor = 'none';
ax.YColor = 'none';

3 绘制花

% 绘制椭圆花瓣
for i = 0:setNum-1iXY = rM^i*cXY;fill(iXY(1,:), iXY(2,:), CList(i+1,:), 'FaceAlpha', .4, 'EdgeColor', 'none');
end
% 绘制白色边缘线
if 1
for i = 0:setNum-1iXY = rM^i*cXY;plot(iXY(1,:), iXY(2,:), 'Color', 'w', 'LineWidth', 1.2);
end
end
fill(cos(cT).*2.3, sin(cT).*2.3, [1,1,1], 'EdgeColor', 'none')


4 绘制文本

% 绘制文本信息
for i = 1:setNumtR = (i-1)*rT/pi*180;if tR>=0 && tR<=180tR = tR-90;elsetR = tR+90;endtext(cos((i-1)*rT).*13, sin((i-1)*rT).*13, num2str(uniq(i)),...'HorizontalAlignment', 'center',...'VerticalAlignment', 'middle',...'Rotation', tR,...numFont{:})text(cos((i-1)*rT).*17, sin((i-1)*rT).*17, setName{i},...'HorizontalAlignment', 'center',...'VerticalAlignment', 'middle',...'Rotation', tR,...labFont{:})
end
text(0, 0, {'core';num2str(core)},...'HorizontalAlignment', 'center',...'VerticalAlignment', 'middle',...labFont{:})


完整代码

% flowerPlotDemo% 给组起名t1 t2 t3...t15
setName = compose('t%d', 1:15);% 随机生成数据
Data = [rand(200, 15) > .1; rand(200, 15) > .85];% 设置字体
numFont = {'FontSize', 14, 'FontName', 'Times New Roman'};
labFont = {'FontSize', 16, 'FontName', 'Times New Roman'};% 设置配色
CList = lines(15);
% C = flowerPlotColor();
% CList = C.CList631;% =========================================================
% 绘图部分代码
% ---------------------------------------------------------
% 数据计算
cT = linspace(0, 2*pi, 200);
cX = cos(cT).*8 + 8;
cY = sin(cT).*3;
cXY = [cX;cY];
setNum = size(Data, 2);
rT = 2*pi./setNum;
rM = [cos(rT),-sin(rT); sin(rT),cos(rT)];uniq = sum(Data.*(sum(Data,2) == 1),1);
core = sum(sum(Data,2) == setNum);figure('Units', 'normalized', 'Position', [.1,.1,.5,.8]);
ax=gca;
ax.NextPlot = 'add';
ax.DataAspectRatio = [1,1,1];
ax.XColor = 'none';
ax.YColor = 'none';% 绘制椭圆花瓣
for i = 0:setNum-1iXY = rM^i*cXY;fill(iXY(1,:), iXY(2,:), CList(i+1,:), 'FaceAlpha', .4, 'EdgeColor', 'none');
end
% 绘制白色边缘线
if 1
for i = 0:setNum-1iXY = rM^i*cXY;plot(iXY(1,:), iXY(2,:), 'Color', 'w', 'LineWidth', 1.2);
end
end
fill(cos(cT).*2.3, sin(cT).*2.3, [1,1,1], 'EdgeColor', 'none')% 绘制文本信息
for i = 1:setNumtR = (i-1)*rT/pi*180;if tR>=0 && tR<=180tR = tR-90;elsetR = tR+90;endtext(cos((i-1)*rT).*13, sin((i-1)*rT).*13, num2str(uniq(i)),...'HorizontalAlignment', 'center',...'VerticalAlignment', 'middle',...'Rotation', tR,...numFont{:})text(cos((i-1)*rT).*17, sin((i-1)*rT).*17, setName{i},...'HorizontalAlignment', 'center',...'VerticalAlignment', 'middle',...'Rotation', tR,...labFont{:})
end
text(0, 0, {'core';num2str(core)},...'HorizontalAlignment', 'center',...'VerticalAlignment', 'middle',...labFont{:})

这篇关于MATLAB | 情人节画个花瓣venn图?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/706763

相关文章

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测

时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测 目录 时序预测 | MATLAB实现LSTM时间序列未来多步预测-递归预测基本介绍程序设计参考资料 基本介绍 MATLAB实现LSTM时间序列未来多步预测-递归预测。LSTM是一种含有LSTM区块(blocks)或其他的一种类神经网络,文献或其他资料中LSTM区块可能被描述成智能网络单元,因为

MATLAB算法实战应用案例精讲-【数模应用】三因素方差

目录 算法原理 SPSSAU 三因素方差案例 1、背景 2、理论 3、操作 4、SPSSAU输出结果 5、文字分析 6、剖析 疑难解惑 均方平方和类型? 事后多重比较的类型选择说明? 事后多重比较与‘单独进行事后多重比较’结果不一致? 简单效应是指什么? 边际估计均值EMMEANS是什么? 简单简单效应? 关于方差分析时的效应量? SPSSAU-案例 一、案例

鹅算法(GOOSE Algorithm,GOOSE)求解复杂城市地形下无人机避障三维航迹规划,可以修改障碍物及起始点(Matlab代码)

一、鹅算法 鹅优化算法(GOOSE Algorithm,GOOSE)从鹅的休息和觅食行为获得灵感,当鹅听到任何奇怪的声音或动作时,它们会发出响亮的声音来唤醒群中的个体,并保证它们的安全。 参考文献 [1]Hamad R K, Rashid T A. GOOSE algorithm: a powerful optimization tool for real-world engineering

基于NURBS曲线的数据拟合算法matlab仿真

目录 1.程序功能描述 2.测试软件版本以及运行结果展示 3.核心程序 4.本算法原理 4.1NURBS曲线基础 4.2 数据拟合原理 5.完整程序 1.程序功能描述        基于NURBS曲线的数据拟合算法,非均匀有理B样条(Non-Uniform Rational B-Splines,简称NURBS)曲线是一种强大的数学工具,广泛应用于计算机图形学、CAD/CA

matlab sift算法使用的记录

最近在做个三维建模的东西,用到了sift算子,需要在matlab上使用。网上介绍使用了 David Lowe的源代码。源码地址为: http://www.cs.ubc.ca/~lowe/keypoints/ 在使用的过程中,会出现以下错误: 不知道是为什么,在一片博客中看到图像大小大致要800*600的说明,我就猜想是不是因为我的图像太大了。原始图像3000*1200的,于是我就把图

详细解析MATLAB和Simulink中的文件格式:mat, mdl, mexw32, 和 m 文件

matlab 探索MATLAB和Simulink中的文件格式:MAT, MDL, MEXW32, 和 M 文件**MAT 文件 (.mat)****MDL 文件 (.mdl)****MEX 文件 (.mexw32/.mexw64)****M 文件 (.m)****总结** 探索MATLAB和Simulink中的文件格式:MAT, MDL, MEXW32, 和 M 文

Matlab中巧用LaTex

Matlab图形中title、xlabel、ylabel、zlabel、textbox和legend等的Interpreter属性有三个属性:latex 、tex、none。默认为tex。 当键入:>> set(text,'Interpreter') Matlab将返回'Interpreter'所包含的属性值: [ latex | {tex} | none ]。 利用Matlab文本的Interp

matlab fspecial 用法解释

fspecial 函数用于建立预定义的滤波算子,其语法格式为: h = fspecial(type) h = fspecial(type , para) 其中 type 指定算子的类型, para 指定相应的参数; type 的类型有: 1 、 'average' averaging filter 为均值滤波,参数为 hsize 代表模板尺寸

MATLAB取整函数

1)fix(x) : 截尾取整. >> fix( [3.12 -3.12]) ans =      3    -3 (2)floor(x):不超过x 的最大整数.(高斯取整) >> floor( [3.12 -3.12]) ans =      3    -4 (3)ceil(x) : 大于x 的最小整数 >> ceil( [3.12 -3.12])

matlab filter2和imfilter有什么区别

imfilter 可进行多维图像(RGB等)进行空间滤波,且可选参数较多 filter2 只能对二维图像(灰度图)进行空间滤波 两个函数结果类型不一样,只需要在I1=filter2(h,I)后面加上I1=uint8(I1)进行类型转换,结果就是一样的。  imfilter N-D filtering of multidimensional images.     B = imfilte