MATLAB中绘制双y散点图
时间: 2023-09-16 18:12:04 浏览: 172
在MATLAB中绘制双y散点图,可以使用`yyaxis`函数来实现。下面是一个简单的示例代码:
```matlab
% 创建一些示例数据
x = 1:10;
y1 = randi([1, 10], 1, 10);
y2 = randi([20, 30], 1, 10);
% 创建图形窗口并绘制散点图
figure;
scatter(x, y1, 'b'); % 绘制蓝色散点图
hold on; % 保持图形窗口
scatter(x, y2, 'r'); % 绘制红色散点图
% 设置左右y轴标签和颜色
yyaxis left;
ylabel('Y1');
yyaxis right;
ylabel('Y2');
% 添加图例
legend('Y1', 'Y2');
% 设置标题和轴标签
title('双y散点图');
xlabel('X');
```
这段代码将会在一个新的图形窗口中绘制双y散点图,其中Y1的散点用蓝色表示,Y2的散点用红色表示。左侧y轴表示Y1的值,右侧y轴表示Y2的值。
相关问题
matlab绘制双y轴折线图
在Matlab中,您可以使用yyaxis函数来创建双y轴折线图。首先,您可以使用yyaxis left命令创建左侧的y轴,并在该轴上绘制您的数据。例如,您可以使用以下代码创建一个基于左侧y轴的折线图:
```
x = linspace(0,25);
y = sin(x/2);
yyaxis left
plot(x, y)
```
接下来,您可以使用yyaxis right命令创建右侧的y轴,并在该轴上绘制另一组数据。例如,您可以使用以下代码在右侧y轴上绘制另外一组数据:
```
rr1 = exp(x/6);
rr2 = exp(x/8);
yyaxis right
plot(x, rr1, x, rr2)
```
这样,您就可以在同一图表上同时显示左右两侧的y轴折线图了。\[2\]\[3\]
#### 引用[.reference_title]
- *1* *2* *3* [Matlab绘制包含双Y轴的图](https://blog.csdn.net/qingfengxd1/article/details/120122017)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
matlab中绘制三维散点图
在 MATLAB 中,可以使用 `scatter3` 函数绘制三维散点图。下面是一个简单的例子:
```matlab
% 生成随机数据
x = randn(100,1);
y = randn(100,1);
z = randn(100,1);
% 绘制散点图
scatter3(x,y,z);
```
这个例子将生成 100 个随机的三维坐标,并使用 `scatter3` 函数绘制它们的散点图。你可以使用其他选项来调整散点图的颜色、大小和样式。例如,你可以使用以下命令将散点的大小设置为 50,颜色设置为红色:
```matlab
scatter3(x,y,z,50,'r','filled');
```
这将在三维空间中绘制一个红色的散点图,并将散点的大小设置为 50。`'filled'` 选项将填充散点的颜色。
阅读全文
相关推荐













