How to set both yticks(left and right) in decimal values not exponential or scientific??

조회 수: 6 (최근 30일)
I have a problem in setting yticks in decimal form.The code works for single y-axis.But when I try to use it in both y-axis(left and right) ,it shows me an error(Assigning to 2 elements using a simple assignment statement is not supported. Consider using comma-separated list assignment).The code:
F = openfig('energy vs time.fig');
hold on;
% Get the current axes handle
ax1 = gca;
% Create a copy of the axes on the right side
ax2 = gca;
% Set the y-axis exponent to 0 for both axes
ax1.YAxis.Exponent = 0;
ax2.YAxis.Exponent = 0;
axis square;

채택된 답변

Dyuman Joshi
Dyuman Joshi 2024년 2월 2일
이동: Dyuman Joshi 2024년 2월 2일
Use get on the axes handle to see its structure - You will find that the YAxis is stored as 2x1 Numeric Ruler (1 for each side).
Use the appropriate index to make changes to the corresponding y-axis.
F = openfig('energy vs time.fig','visible');
hold on;
% Get the current axes handle
ax = gca;
get(ax)
ALim: [0 1] ALimMode: 'auto' AlphaScale: 'linear' Alphamap: [0 0.0159 0.0317 0.0476 0.0635 0.0794 0.0952 0.1111 0.1270 0.1429 0.1587 0.1746 0.1905 0.2063 0.2222 0.2381 0.2540 0.2698 0.2857 0.3016 0.3175 0.3333 … ] (1×64 double) AmbientLightColor: [1 1 1] BeingDeleted: off Box: on BoxStyle: 'back' BusyAction: 'queue' ButtonDownFcn: '' CLim: [0 1] CLimMode: 'auto' CameraPosition: [47.5000 -57350 8.1603] CameraPositionMode: 'auto' CameraTarget: [47.5000 -57350 -0.5000] CameraTargetMode: 'auto' CameraUpVector: [0 1 0] CameraUpVectorMode: 'auto' CameraViewAngle: 6.6086 CameraViewAngleMode: 'auto' Children: [1×1 Line] Clipping: on ClippingStyle: 'rectangle' Color: [1 1 1] ColorOrder: [0 0 0] ColorOrderIndex: 1 ColorScale: 'linear' Colormap: [256×3 double] ContextMenu: [0×0 GraphicsPlaceholder] CreateFcn: '' CurrentPoint: [2×3 double] DataAspectRatio: [105 3300 1] DataAspectRatioMode: 'auto' DeleteFcn: '' FontAngle: 'normal' FontName: 'Helvetica' FontSize: 14 FontSizeMode: 'manual' FontSmoothing: on FontUnits: 'points' FontWeight: 'bold' GridAlpha: 0.5000 GridAlphaMode: 'manual' GridColor: [0.1500 0.1500 0.1500] GridColorMode: 'auto' GridLineStyle: '-' GridLineWidth: 1.5000 GridLineWidthMode: 'auto' HandleVisibility: 'on' HitTest: on InnerPosition: [0.1300 0.1100 0.7750 0.8150] InteractionOptions: [1×1 matlab.graphics.interaction.interactionoptions.InteractionOptions] Interactions: [1×1 matlab.graphics.interaction.interface.DefaultAxesInteractionSet] Interruptible: on LabelFontSizeMultiplier: 1.1000 Layer: 'bottom' Layout: [0×0 matlab.ui.layout.LayoutOptions] Legend: [1×1 Legend] LineStyleCyclingMethod: 'aftercolor' LineStyleOrder: [7×2 char] LineStyleOrderIndex: 1 LineWidth: 1.5000 MinorGridAlpha: 0.5000 MinorGridAlphaMode: 'manual' MinorGridColor: [0.1000 0.1000 0.1000] MinorGridColorMode: 'auto' MinorGridLineStyle: ':' MinorGridLineWidth: 1.5000 MinorGridLineWidthMode: 'auto' NextPlot: 'add' NextSeriesIndex: 0 OuterPosition: [0 0 1 1] Parent: [1×1 Figure] PickableParts: 'visible' PlotBoxAspectRatio: [1 1 1] PlotBoxAspectRatioMode: 'manual' Position: [0.1300 0.1100 0.7750 0.8150] PositionConstraint: 'outerposition' Projection: 'orthographic' Selected: off SelectionHighlight: on SortMethod: 'childorder' Subtitle: [1×1 Text] SubtitleFontWeight: 'normal' Tag: '' TickDir: 'in' TickDirMode: 'auto' TickLabelInterpreter: 'tex' TickLength: [0.0100 0.0250] TightInset: [0 0.0603 0 0.0675] Title: [1×1 Text] TitleFontSizeMultiplier: 1.1000 TitleFontWeight: 'bold' TitleHorizontalAlignment: 'center' Toolbar: [1×1 AxesToolbar] Type: 'axes' Units: 'normalized' UserData: [] View: [0 90] Visible: on XAxis: [1×1 NumericRuler] XAxisLocation: 'bottom' XColor: [0.1500 0.1500 0.1500] XColorMode: 'auto' XDir: 'normal' XGrid: off XLabel: [1×1 Text] XLim: [-5 100] XLimMode: 'manual' XLimitMethod: 'tickaligned' XMinorGrid: off XMinorTick: on XScale: 'linear' XTick: [0 20 40 60 80 100] XTickLabel: {6×1 cell} XTickLabelMode: 'auto' XTickLabelRotation: 0 XTickLabelRotationMode: 'auto' XTickMode: 'manual' YAxis: [2×1 NumericRuler] YAxisLocation: 'left' YColor: [0 0 0] YColorMode: 'manual' YDir: 'normal' YGrid: off YLabel: [1×1 Text] YLim: [0 2700] YLimMode: 'manual' YLimitMethod: 'tickaligned' YMinorGrid: off YMinorTick: on YScale: 'linear' YTick: [0 500 1000 1500 2000 2500] YTickLabel: {6×1 cell} YTickLabelMode: 'auto' YTickLabelRotation: 0 YTickLabelRotationMode: 'auto' YTickMode: 'auto' ZAxis: [1×1 NumericRuler] ZColor: [0.1500 0.1500 0.1500] ZColorMode: 'auto' ZDir: 'normal' ZGrid: off ZLabel: [1×1 Text] ZLim: [-1 0] ZLimMode: 'manual' ZLimitMethod: 'tickaligned' ZMinorGrid: off ZMinorTick: on ZScale: 'linear' ZTick: [-1 -0.5000 0] ZTickLabel: '' ZTickLabelMode: 'auto' ZTickLabelRotation: 0 ZTickLabelRotationMode: 'auto' ZTickMode: 'auto'
%Change the exponent of the 2nd y-axis
ax.YAxis(2).Exponent = 0;

추가 답변 (1개)

chicken vector
chicken vector 2024년 2월 2일
F = openfig('energy vs time.fig');
ax = gca;
ax.YAxis(1).Exponent = 0;
ax.YAxis(2).Exponent = 0;
axis square;

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by