I have created a subplot with many different diagrams. Now i want to set the coordinates range.

2 次查看(过去 30 天)
Thank you for your previous help. Here my last question regarding this topic. Thank you in advance :) BR Mueller Philipp
Matlab sets automat. the x/y range of the diagram depending on the input data. I want to set it manually. Matlab should not set it.
axis ([ -500 500 0 222]); This command does not work.
If i use this command all other diagrams are also involved and changed.
I want for each diagram own limits for x and y (z).
clear all %löscht alle Variablen
clear clc %löscht den Bildschirm
%Subplot Einstellungen
%fig = figure;
%fig.Units = 'centimeters';
%fig.Position(3:4) = [25 25];
%ax11 = axes('units', 'centimeters', 'position', [ 3, 21, 7, 7]);%Spalte 1 Reihe 1
%ax12 = axes('units', 'centimeters', 'position', [ 12, 21, 7, 7]);%Spalte 2 Reihe 1
%ax21 = axes('units', 'centimeters', 'position', [ 3, 12, 7, 7]);%Spalte 1 Reihe 2
%ax22 = axes('units', 'centimeters', 'position', [ 12, 12, 7, 7]);%Spalte 2 Reihe 2
%ax31 = axes('units', 'centimeters', 'position', [ 3, 3, 7, 7]);%Spalte 1 Reihe 3
%ax32 = axes('units', 'centimeters', 'position', [ 12, 3, 7, 7]);%Spalte 2 Reihe 3
fig = figure;
fig.Units = 'centimeters';
fig.Position(3:4) = [25 25];
plotPositions = [ 3, 21, 7, 7;
12, 21, 7, 7;
3, 12, 7, 7;
12, 12, 7, 7;
3, 3, 7, 7;
12, 3, 7, 7];
for i = 1:length(plotPositions)
plotHandle = subplot(3, 2, i);
plotHandle.Units = 'centimeters';
plotHandle.Position = plotPositions(i,:);
end
%RAINFLOWDARSTELLUNG%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Input_Matrix = textread('Input1.txt')%liest die Daten für die Rainflow Darstellung ein
[zeilen,spalten]=size(Input_Matrix)
x = Input_Matrix(:,1)
y = Input_Matrix(:,2)
z = Input_Matrix(:,3)
%Definiert mir den Range des Diagramms...
axis ([ -500 500 0 222]);%manuelle Festlegung der Grenzen, hier solltest du
%die jeweiligen höheren Werte der Funktionen eintragen....... Was ist
%grösser? Rainflow oder Cutoff?
%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
az = 0;
el = 90;
view(az, el);
hold on
view(0,90)% view from above !!!http://de.mathworks.com/help/matlab/ref/view.html
a = 12;%markersize kannst einstellen welche grösse du haben willst ...
%subplot(ax12)
subplot(3,2,2)
%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
scatter3(x, y, z, a, z, 'filled')
hold on
view(0, 90)
%Hier macht er die richtige sortierung für die korrekte darstellung.
%value = find(max(z)) ;
%hold on
%plot3(x(idx),y(idx),z(idx),'*r')
[m,ind]=max(z);
%subplot(ax12)
%subplot(3,2,2)
%colorbar('location','Manual', 'position', [0.93 0.1 0.02 0.81]);
colorbar
scatter3(x(ind), y(ind), z(ind),'*r');
grid on;%Gitter eingeschalten...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%***************** Wie man eine Linie zeichnet - Allgemeine Erklärung ***************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Hier die dicke braune "dummy Linie"
line([-350 -150],[20 20],[1000000000000 1000000000000],'Marker','.','LineStyle','-','LineWidth',9, 'Color',[.5 .4 .3])
%***************** Ende **************************************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%********************Cutofflinien zeichnen********************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
%Initialisierungen für die Berechnungen:***********************************
sigma_wk = 50; % Default Wert angenommen
tau_wk = 70; % Default Wert angenommen
m_sigma = 0.07; % Steigung - Defaultwert angenommen
m_tau = 0.07; % Steigung - Defaultwert angenommen
m_sigma_zwei = m_sigma*0.33; % Steigung etwas flacher -> 1/3 von m_sigma -> vom Punkt 2 nach 3
m_tau_zwei = m_tau*0.33; % Steigung etwas flacher -> 1/3 von m_sigma -> vom Punkt 2 nach 3
multipikator=1.2;% Für das Zeichnen der Waagrechten Linien
%Normalspannungen:*********************************************************
%X-Koordianten der einzelnen Punkte
sigma_m_1=sigma_wk/(m_sigma-1);%Punkt1
sigma_m_2=sigma_wk/(1+m_sigma);%Punkt2
sigma_m_3=sigma_wk*((3+m_sigma)/(1+m_sigma_zwei)^2);%Punkt3
%Y-Werte der Punkte der einzelnen Punkte
sigma_a_1=sigma_wk/(1-m_sigma);%Punkt1
sigma_a_2=sigma_wk/(1+m_sigma);%Punkt2 Vorzeichen plus gemacht!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
sigma_a_3=(sigma_wk/3)*((3+m_sigma)/(1+m_sigma)^2);%Punkt3
%Schubspannungen***********************************************************
%X-Koordianten der einzelnen Punkte
tau_m_1=tau_wk/(m_tau-1);
tau_m_2=tau_wk/(1+m_tau);
tau_m_3=tau_wk*((3+m_tau)/(1+m_tau_zwei)^2);%
%Y-Werte der Punkte der einzelnen Punkte
tau_a_1=tau_wk/(1-m_tau);
tau_a_2=tau_wk/(1+m_tau);
tau_a_3=(tau_wk/3)*((3+m_tau)/(1+m_tau)^2);
%Diagramm Beschriftungen***************************************************
%Farbauswahl http://www.avatar.se/molscript/doc/colour_names.html
title('\color[rgb]{0.698039 0.133333 0.133333}Normalspannungen - Schubspannungen');%Titel des Diagrammes.
ylabel('Beschriftung der y - Achse \color[rgb]{0 0.392157 0}\bf\sigma_{a}\tau_{a}');
xlabel('Beschriftung der x - Achse \color[rgb]{0 0.392157 0}\bf\sigma_{m}\tau_{m}');
grid on; %Gitter eingeblendet
%axis ([ -5 5 0 5]);%manuelle Festlegung der
%Grenzen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%axis tight ;%Mit "..." werden die Bereiche wieder so gesetzt, dass die Daten perfekt in den Plot passen.
%Griechische Buchstaben https://de.mathworks.com/help/matlab/creating_plots/greek-letters-and-special-characters-in-graph-text.html?searchHighlight=greek
%http://matlab.izmiran.ru/help/techdoc/ref/linespec.html
%**************************************************************************
%Jetzt wird gezeichnet Schubspannungen und Normalspannungen (in einem Diagram )****************************************************
% X-Werte, Y-Werte, Z-Werte %Hier werden 2 Punkte im 3D Raum miteinander verbunden.....
%Z-Koordinaten wurde defaultmässig auf 1e7 gesetzt damit die cutoff linien
%deckend sind.
%Die Benennung der Punkte habe ich von der übernommen....
line([0 sigma_m_2],[sigma_wk sigma_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[1 0 0])% 0-2
line([sigma_m_2 sigma_m_3],[sigma_a_2 sigma_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[0 1 0])%2-3
line([0 sigma_m_1],[sigma_wk sigma_a_1],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',1, 'Color',[0 0 1])%0-1
%Waagrechte Linien: (mit dem Multiplikator habe ich defaultmässig
line([sigma_m_3 sigma_m_3*multipikator],[sigma_a_3 sigma_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])%Rechts
line([sigma_m_1 sigma_m_1*multipikator],[sigma_a_1 sigma_a_1],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])%Links
%Schubspannungen***********************************************************
line([0 tau_m_2],[tau_wk tau_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 1 1])
line([tau_m_2 tau_m_3],[tau_a_2 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 0 1])
line([0 -tau_m_2],[tau_wk tau_a_2],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[1 0 1])
line([-tau_m_2 -tau_m_3],[tau_a_2 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',5, 'Color',[0 1 1])
line([tau_m_3 tau_m_3*multipikator],[tau_a_3 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])% %Waagrechte Linien: Rechts
line([-tau_m_3 -tau_m_3*multipikator],[tau_a_3 tau_a_3],[1e7 1e7],'Marker','.','LineStyle','-','LineWidth',3, 'Color',[1 0 0])% %Waagrechte Linien: Links
%****************************************************************************************
%****************************************************************************************
%****************************************************************************************
hold off
%WÖHLER
Input_Matrix_Woehler = textread('2.txt')
x1 = Input_Matrix_Woehler(:,1)
y1 = Input_Matrix_Woehler(:,2)
%xlim(axes1,[1000 200000000]);
%axis ([ 1000 1e7 0 130]);
% Create semilogx
% Uncomment the following line to preserve the X-limits of the axes
[xb,yb] = stairs(x1,y1);
%plot(xb,yb)
%CREATEFIGURE(X1, Y1)
% X1: vector of x data
% Y1: vector of y data
% Auto-generated by MATLAB on 26-Sep-2016 15:00:15
% Create figure
%figure1 = figure('Name','Woehler',...
% 'Color',[0.756862759590149 0.866666674613953 0.776470601558685]);
% Create axes
%axes1 = axes('Parent',figure1);
%hold(axes1,'on');
% Create semilogx
% Uncomment the following line to preserve the X-limits of the axes
% xlim(axes1,[1000 200000000]);
%box(axes1,'on');
% Set the remaining axes properties
%set(axes1,'Color',[0.894117653369904 0.941176474094391 0.901960790157318],...
% 'XMinorTick','on','XScale','log');
%axis ([ 1000 200000000 0 120]);%manuelle Festlegung der Grenzen, hier solltest du
%subplot(ax11)
subplot(3,2,1)
%plot(yb,xb)
%axis(ax,'manual',1000 1e7 0 130)
plot(yb,xb)
%plot(x1,y1)
%http://stackoverflow.com/questions/15814068/pcolor-in-scatter-plot-matlab
%https://plot.ly/alpha/workspace/
%[dummy ID]=sort(z);
%colors=colormap(jet(length(z)));
%figure
%for i=1:length(z)
%plot(x(i),y(i),'s','MarkerFaceColor',colors(ID(i),:));
%hold on
%end
subplot(3,2,3)
subplot(3,2,4)
subplot(3,2,5)
subplot(3,2,6)
datacursormode on %damit ich die punkte im diagram anclicken kann und die jeweiligen werte angezeigt bekomme .....
%figure('units','centimeters','position',[3 3 5 5])

采纳的回答

Nick Counts
Nick Counts 2016-11-8
Philip,
I am unable to reproduce your issue with | axis ([ -500 500 0 222])| changing the limits of all plots.
However, you can specify the axes on which axis or xlim operate as follows:
axis(subplot(3,2,5), [0 20 0 10])
xlim(subplot(3,2,5), [0 10])
Hopefully this will help you.
  1 个评论
dpb
dpb 2016-11-8
编辑:dpb 2016-11-8
While the above works to address the given subplot, it masks the more fundamental issue that OP's code destroys the axes handles for previous subplot axes retaining only the last. This likely will be an issue in other properties and certainly makes enhancement/revision of the script much more difficult than using the handles themselves directly.
While the subplot(N,M,i) notation in this syntax does return the particular subplot handle by reexamining the currently existing locations, that's additional effort if just save the handles w/o overwriting the array initially.

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2016-11-8
...
for i = 1:length(plotPositions)
plotHandle = subplot(3, 2, i);
...
The above is the root of your problems...you're overwriting the axes handle of each subplot into the same variable, thus losing access to all of them excepting the last one. Create and use each separately to ensure do what you want on each axes object.
...
nPlots=length(plotPositions); % shorthand variable for convenience
hAx=zeros(nPlots,1); % preallocate array for axes/subplot handles
for i = 1:nPlots
hAx(i)=subplot(3, 2, i); % and save each so don't lose any of 'em...
...
% do whatever to create subplot here...
axis(hAx(i),[ -500 500 0 222]); % will set for current axes only
...
end
Of course, if each is to have its own set of limits, then you need the numeric values in the axis statement to reflect the proper ones for that axis; if they're known a priori then an array would be one way to hold the values; otherwise compute them from the data or get from user or whatever. The key is still to apply the desired set to the axis intended and only to that axis. Using the explicit handle will solve that issue (and probably many others for other properties as well). Otherwise, HG commands will operate on whichever axis happens to be current which can change at will with user interaction or, as in your code, to the last one created because that's what that handle variable you kept refers to if you use it.
See the last portion of the doc for axes where it says...
>> help axis
axis Control axis scaling and appearance.
axis([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes
on the current plot.
...
axis(H,...) changes the axes handles listed in vector H.
...

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by