Plotting different chart types in the same figure?

조회 수: 1 (최근 30일)
Francisco Mendes
Francisco Mendes 2015년 11월 16일
편집: Yazan 2021년 7월 13일
Hello Matlab community. I am a basic Matlab user and I am very interested about plotting in Matlab.
I would like to know if is it possible to plot different chart types in the same figure? And if yes, how to do it?
Here's an example: Let's suppose I would like to plot an Histogram to compare different data.
At the same time I have a specification limit for the data I am analysing and I would like to plot the limit as a continuous line in the same chart just to check if any histogram bars would pass it.
Thank you in advance.

답변 (3개)

Jan
Jan 2015년 11월 16일
You can create either different axes objects directly using the axes('Position', [X, Y, W, H]]) command. Or the subplot() command does this also internally, but uses an easier syntax to determin the positions. Reading the documentation for the commands will help, most of all the examples there.

Star Strider
Star Strider 2015년 11월 16일
To plot two different plots on the same axes, use the hold function:
figure(1)
histogram( ... )
hold on
plot(xlim, [1 1]*limit_line_value,'-r')
hold off

Yazan
Yazan 2021년 7월 13일
편집: Yazan 2021년 7월 13일
There are several ways to obtain that. One of them is through creating panels, each with its own axes. You can plot on the axes separately. Remember, pannels are children of a figure (or a uitab), the axes are children of a panel, and the data are children of the axes. An example is provided below, which plots the histogram of a random vector and the data itself on different panels.
% figure: father of the panels
f = figure;
% panels: children of a figure and father to axes
p1 = uipanel(f, 'Position', [0 0 0.5 1], 'Title', 'First panel', 'TitlePosition', 'centertop');
p2 = uipanel(f, 'Position', [0.5 0 0.5 1], 'Title', 'Second Panel', 'TitlePosition', 'centertop');
x = randn(128, 1);
% create axes on each panel
ax1 = axes(p1);
% specify the axes on which to plot the histogram
histogram(ax1, x);
xlabel(ax1, 'Bins'); ylabel(ax1, 'Histogram');
ax2 = axes(p2);
% specify the axes on which to plot the data
plot(ax2, x);
xlabel(ax2, 'Index'); ylabel(ax2, 'Data');

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by