MATLAB | MATLAB中绘图的奇淫技巧合集
一些离大谱的绘图小技巧,部分内容来自https://undocumentedmatlab.com/
更改3D坐标区轴位置
对于hAxes=gca
- hAxes.XRuler.FirstCrossoverValue
X轴在Y轴上的位置 - hAxes.XRuler.SecondCrossoverValue
X轴在Z轴上的位置 - hAxes.YRuler.FirstCrossoverValue
Y轴在X轴上的位置 - hAxes.YRuler.SecondCrossoverValue
Y轴在Z轴上的位置 - hAxes.ZRuler.FirstCrossoverValue
Z轴在X轴上的位置 - hAxes.ZRuler.SecondCrossoverValue
Z轴在Y轴上的位置
一个实例:
N = 49;
X = linspace(-10,10,N);
Z = peaks(N);
mesh(X,X,Z);hAxes=gca;
hAxes.LineWidth=1.5;
hAxes.XRuler.FirstCrossoverValue = 0; % X轴在Y轴上的位置
hAxes.YRuler.FirstCrossoverValue = 0; % Y轴在X轴上的位置
hAxes.ZRuler.FirstCrossoverValue = 0; % Z轴在X轴上的位置
hAxes.ZRuler.SecondCrossoverValue = 0; % Z轴在Y轴上的位置
无穷基线
基线不仅可以设置为0或者其他有限数,甚至可以设置为正负无穷:
x=0:.1:8;
y=sin(x)-x;area(x,y,'FaceAlpha',.5,'BaseValue',-inf)
x=1900:10:2000;
y=[75 91 105 123.5 131 150 179 203 226 249 281.5];
bar(x,y,'BaseValue',inf)
修改坐标区域背景
我们知道可以通过设置
set(gca,'Color',[1,0,0])
类似的形式设置背景颜色,但这只是纯色,那么有啥办法把背景色换成渐变色?
t=0.2:0.01:3*pi;hold on
plot(t,cos(t)./(1+t),'LineWidth',4)
plot(t,sin(t)./(1+t),'LineWidth',4)
plot(t,cos(t+pi/2)./(1+t+pi/2),'LineWidth',4)
plot(t,cos(t+pi)./(1+t+pi),'LineWidth',4)
legendax=gca;pause(1e-16);% Backdrop建立需要一定时间因此pause一下很重要
% 四列分别为四个角的颜色
% 使用4xN大小颜色矩阵
% 四行分别是R,G,B,和透明度
colorData = uint8([255, 150, 200, 100; ... 255, 100, 50, 200; ...0, 50, 100, 150; ...102, 150, 200, 50]);
set(ax.Backdrop.Face, 'ColorBinding','interpolated','ColorData',colorData);
修改背景为图片
t=0.2:0.01:3*pi;hold on
plot(t,cos(t)./(1+t),'LineWidth',4)
plot(t,sin(t)./(1+t),'LineWidth',4)
plot(t,cos(t+pi/2)./(1+t+pi/2),'LineWidth',4)
plot(t,cos(t+pi)./(1+t+pi),'LineWidth',4)
legendaxis tight;
img=imread('test.png');
h=image(xlim,ylim,flipud(img));
uistack(h,'bottom')
循环颜色和线形
ax=gca;hold on
m=magic(9);ax.ColorOrder=lines(3);
ax.LineStyleOrder={'-','--o',':s'};hold on
for i=1:9plot(m(i,:),'LineWidth',1.2)ax.LineStyleOrderIndex = ax.ColorOrderIndex;
end
legend
渐变marker
x=1:30;y=sin(x);
hLine=plot(x,y,'o-','MarkerSize',10,'Color',[0,0,0]);pause(1e-16)% MarkerHandle建立需要一定时间因此pause一下很重要
hMarkers=hLine.MarkerHandle;
markerNum=size(hMarkers.VertexData,2);% 这里用的pink配色,可以换成其他colormap
colorData=uint8([(pink(markerNum).*255)';255.*ones(1,markerNum)]);
set(hMarkers,'FaceColorBinding','interpolated','FaceColorData',colorData)
渐变折线图
x=1:.1:10;y=sin(x);
hLine=plot(x,y,'-','LineWidth',30);colorNum=length(hLine.XData);% 这里用的pink配色,可以换成其他colormap
% 最后面透明度用的200可调整
colorData=uint8([(pink(colorNum).*255)';200.*ones(1,colorNum)]);
pause(1e-16)% MarkerHandle建立需要一定时间因此pause一下很重要
set(hLine.Edge,'ColorBinding','interpolated', 'ColorData',colorData)
半透明及渐变图例
t=0.2:0.01:3*pi;hold on
plot(t,cos(t)./(1+t),'LineWidth',4)
plot(t,sin(t)./(1+t),'LineWidth',4)
plot(t,cos(t+pi/2)./(1+t+pi/2),'LineWidth',4)
plot(t,cos(t+pi)./(1+t+pi),'LineWidth',4)
hLegend=legend();
% 设置图例为半透明
pause(1e-16)
set(hLegend.BoxFace,'ColorType','truecoloralpha','ColorData',uint8(255*[1;1;1;.5])); set(gca,'Color',[0,0,.18]);
当然也可以花里胡哨:
t=0.2:0.01:3*pi;
hold on
plot(t,cos(t)./(1+t),'LineWidth',4)
plot(t,sin(t)./(1+t),'LineWidth',4)
plot(t,cos(t+pi/2)./(1+t+pi/2),'LineWidth',4)
plot(t,cos(t+pi)./(1+t+pi),'LineWidth',4)
hLegend=legend();% 设置图例为渐变色
pause(1e-16)
colorData = uint8([255, 150, 200, 100; ... 255, 100, 50, 200; ...0, 50, 100, 150; ...102, 150, 200, 50]);
set(hLegend.BoxFace,'ColorBinding','interpolated','ColorData',colorData)
特殊marker
众所周知,在版本R2020b版本中,横线及竖线marker以及可以直接使用:
t=0:0.1:3*pi;
hold on
plot(t,cos(t),'-_')
plot(t,t./8,'-|')
而在老版本,这俩marker可以这样调用出来:
t=0:0.1:3*pi;
hold on
hLine1=plot(t,cos(t),'-o');
hLine2=plot(t,t./8,'-o');pause(1e-8)
set(hLine1.MarkerHandle,'Style','hbar')
set(hLine2.MarkerHandle,'Style','vbar')
等高线图保留小数位数
[X,Y,Z] = peaks;[c,h]=contourf(X,Y,Z,5,'ShowText','on');
h.LevelList=round(h.LevelList,3);% 保留三位小数
clabel(c,h)
绘制结果:
原始绘图:
根据等高线颜色设置文本颜色
[X,Y,Z] = peaks;
[C,hContour] = contour(X,Y,Z, 'ShowText','on', 'LevelStep',1, 'LineWidth',1.5);updateContours(hContour);
% 因为标签位置是自动更新的属性,会刷新掉颜色,因此添加listener检测
addlistener(hContour, 'MarkedClean', @(h,e)updateContours(hContour));
function updateContours(hContour)drawnow levels = hContour.LevelList;labels = hContour.TextPrims; % 获取标签基础对象 lines = hContour.EdgePrims; % 获取边缘基础对象 for idx = 1 : numel(labels)labelValue = str2double(labels(idx).String);lineIdx = find(abs(levels-labelValue)<10*eps, 1); % 找到对应层级labels(idx).ColorData = lines(lineIdx).ColorData; % 修改标签颜色labels(idx).Font.Size = 11;enddrawnow
end
MATLAB | MATLAB中绘图的奇淫技巧合集相关推荐
- [存档]Div+Css布局中经常使用的小技巧合集
CSS网页布局开发中,会有很多小技巧,这里再扩展一下您所想要得到的知识,相信您会有很多收获! 一.ul标签在Mozilla中默认是有padding值的,而在IE中只有margin有值. 二.同一个的c ...
- powerdesigner奇淫技
在日常开发中数据库的设计常常需要建立模型,而powerdesigner是个不错的选择.但很多时候用powerdesigner生成模型后再去创建表结构,会觉得烦和别扭.那么能不能数据库表建好后再生成模型 ...
- 源码解析中看到的奇淫巧技
源码解析中看到的奇淫巧技 一. 数组重置 let arr = [123,123] arr.length // 2 arr.length = 0 arr // [] 当我们给数组的length 属性设置 ...
- 华为手机音量键技巧合集,很少有人全部掌握的7个技巧,你会用吗
华为手机音量键技巧合集,很少有人全部掌握的7个技巧,你会用吗 本文专门为花粉所写,或者说目前正在使用华为手机以及打算入手华为手机的用户们,所提供的华为音量键技巧合集.很少有人能够全部掌握这6个关于音量 ...
- 漏洞挖掘中的各种奇淫技巧(持续更新...)
漏洞 URL跳转漏洞 挖洞技巧:如何绕过URL限制 URL跳转漏洞学习 URL重定向漏洞解析 支付漏洞 挖洞技巧:支付漏洞之总结 SRC众测挖洞之支付逻辑漏洞的奇淫技巧 验证码类 挖洞技巧:绕过短信& ...
- Java中的一些奇淫技巧总结
不用中间变量交换两个数 public class SWapTest {static int a = Integer.MAX_VALUE;static int b = 1;public static v ...
- 中望3D 2021出图进阶版-3D出图技巧合集
一. 隐藏多余线条 双击视图 – "视图属性"对话框中进行设置: "通用"选项卡 – "显示消隐线"按钮关闭: "线条" ...
- 安卓开发替换json字符串中的数据_22个JavaScript开发技巧合集
作者:kancloud 转发链接:https://www.kancloud.cn/dennis/tgjavascript/241855 开发技巧 1.使用var声明变量 如果给一个没有声明的变量赋值, ...
- 关于工作中所需要用到的电子书格式转换技巧合集
随着电子书的普及,人们可以通过各种设备轻松地阅读自己喜欢的书籍. 然而,由于不同设备和软件的支持格式存在差异,有时我们需要将一种格式的电子书转换为另一种格式才能在特定设备或软件上阅读.那大家知道电子书 ...
最新文章
- mysql连接池为何不用nio_为什么要用数据库连接池?
- SQL Server 2014 许可证(五)降级与升级
- MS UC 2013-0-虚拟机-标准化-部署-2-模板机-制作-4
- 蓝桥杯:入门训练 圆的面积
- 百度娱乐沸点颁奖典礼,温度太低的“沸点”
- CmsEasy 漏洞挖掘
- 解决oracle中文数据乱码的问题
- B16_NumPy线性代数(dot,vdot,inner,matmul,determinant,solve,inv)
- 今日头条竞价接口转发
- Stream 工具方法
- 写给自己看的三栏布局的演示
- android动态设置全屏,Android开发之全屏与非全屏的切换设置方法小结
- Unknown initial character set index ‘255‘ received from server.
- STM32CubeMX使用(六)之RTC及制作时间戳
- android按钮放图片不显示文字,Android 自定义标签 Imagebutton实现ImageButton里放置文字...
- 高级操作系统——XV6内存管理
- 15个常用excel函数公式_工作中常用的excel函数公式大全,拿来即用!
- matlab表示双曲函数,MATLAB2009_1_5三角函数和双曲函数
- 利用Python将PDF转化为图片的方法
- 荣耀8X0安卓系统切换鸿蒙系统,华为大改安卓Q,EMUI 10将启用全新UI,花粉沸腾:静候鸿蒙...