필터 지우기
필터 지우기

How can I just change the color of the bottom x-axis of a figure?

조회 수: 59 (최근 30일)
Zhou Ci
Zhou Ci 2023년 11월 18일
댓글: Dyuman Joshi 2023년 11월 23일
I am trying to make a figure where I just want to change the color of the bottom x-axis. My line from the code is:
ax2.XAxis.Color = p.color
Using this gives color to both lower and upper x-axis. How can I keep upper axis black and only bottom x-axis changes? Thank you
  댓글 수: 4
Zhou Ci
Zhou Ci 2023년 11월 18일
This is the output if I turn box 'off'. But I don't want like this

댓글을 달려면 로그인하십시오.

답변 (2개)

Star Strider
Star Strider 2023년 11월 18일
If you just want to change the axis colour, try something like this —
Ax1 = axes;
Ax2 = axes;
Ax2.XAxisLocation = 'top';
Ax1.XColor = 'r';
This works in R2023b.
It would help to have your code and the MATLAB version you are using. See the documentation section on XColor for details.
.
  댓글 수: 3
Star Strider
Star Strider 2023년 11월 22일
It can be made to appear with either:
Ax2.YAxisLocation = 'right';
or:
Ax1.Box = 'on';
or turning it on in ‘Ax2’, depending on what is desired (since it is present in the first image, absent in the second).
Dyuman Joshi
Dyuman Joshi 2023년 11월 23일
The second image is OP showing the result of using the command 'box off''

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2023년 11월 22일
Here is a demo to show you how you can change nearly everything in a plot.
% Demo to make a black graph with red Y axis, green X axis, and yellow grid. Markers are magenta with green lines between them.
% Initialization steps:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 24;
% Create sample data.
X = 1 : 20;
Y = rand(1, 20);
% Plot green lines between the markers.
plot(X, Y, 'g-', 'LineWidth', 3);
hold on;
% Plot magenta markers.
plot(X, Y, 'ms', 'LineWidth', 3, 'MarkerSize', 15);
grid on;
title('Y vs. X, Font Size 20', 'FontSize', 20, 'Color', 'b', 'FontWeight', 'bold');
% Make labels for the two axes.
xlabel('X Axis, Font Size 18');
ylabel('Y axis, Font Size 24');
yticks(0 : 0.2 : 1);
% Get handle to current axes.
ax = gca
ax =
Axes (Y vs. X, Font Size 20) with properties: XLim: [0 20] YLim: [0 1] XScale: 'linear' YScale: 'linear' GridLineStyle: '-' Position: [0.13 0.11 0.775 0.796812933025404] Units: 'normalized' Use GET to show all properties
% Now let's have fun changing all kinds of things!
% This sets background color to black.
ax.Color = 'k';
ax.YColor = 'r';
% Make the x axis dark green.
darkGreen = [0, 0.6, 0];
ax.XColor = darkGreen;
% Make the grid color yellow.
ax.GridColor = 'y';
ax.GridAlpha = 0.9; % Set's transparency of the grid.
% Set x and y font sizes.
ax.XAxis.FontSize = 18;
ax.YAxis.FontSize = 24;
% Make the axes tick marks and bounding box be really thick.
ax.LineWidth = 3;
% Let's have the tick marks go outside the graph instead of poking inwards
ax.TickDir = 'out';
% The below would set everything: title, x axis, y axis, and tick mark label font sizes.
% ax.FontSize = 34;
% Bold all labels.
ax.FontWeight = 'bold';
hold off
% Now do stuff with the figure, as opposed to the axes control that is ON the figure.
% Maximize the figure
g = gcf; % Get handle to the current figure.
g.WindowState = 'maximized'; % Make it full screen.
g.Name = 'Demo by Image Analyst'; % Put a custom string into the titlebar.
g.NumberTitle = 'off'; % Don't have it put "Figure 1" before the name.
g.MenuBar = 'figure'; % or 'none'
g.ToolBar = 'figure'; % or 'none'

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by