How to change image plot tickmark colors

146 visualizaciones (últimos 30 días)
Zihad Azad
Zihad Azad el 10 de En. de 2021
Comentada: Image Analyst el 12 de En. de 2021
Hi there,
I want to add white tickmarks (inward) along both axis without changing the ticklabel and axis label colors. Could anyone please help me do this? Apparently there is no direct solution for this issue. (I am using Matlab 2018a)

Respuestas (1)

Image Analyst
Image Analyst el 10 de En. de 2021
You can change virtually anything. See this demo and adapt as needed:
% 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 betweent the markers.
plot(X, Y, 'g-', 'LineWidth', 2);
hold on;
% Plot magenta markers.
plot(X, Y, 'ms', 'LineWidth', 2, 'MarkerSize', 15);
grid on;
title('Y vs. X, Font Size 12', 'FontSize', 12, 'Color', 'b', 'FontWeight', 'bold');
% Make labels for the two axes.
xlabel('X Axis, Font Size 15');
ylabel('Y axis, Font Size 24');
yticks(0 : 0.2 : 1);
% Get handle to current axes.
ax = gca
% 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 = 15;
ax.YAxis.FontSize = 24;
% 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
% Maximize the figure
g = gcf;
g.WindowState = 'maximized';
  2 comentarios
Zihad Azad
Zihad Azad el 12 de En. de 2021
Thanks for the response. But still, I cannot seem to find a way to change the ticklength color in this code
Image Analyst
Image Analyst el 12 de En. de 2021
I don't think that the length of the tick marks can be increased. You might have to manually draw little lines with the line() function if you want to do that. Here is what I could do:
% Display sample image.
rgbImage = imread('peppers.png');
hFig = figure;
imshow(rgbImage);
axis('on', 'image');
% Set background of figure to black so we can see white tick marks.
hFig.Color = 'k';
hFig.InvertHardcopy = 'off';
title('Title Has Font Size 20', 'FontSize', 20, 'Color', 'y', 'FontWeight', 'bold');
% Make labels for the two axes.
xlabel('X Axis, Font Size 20');
ylabel('Y axis, Font Size 20');
% Get handle to current axes that is sitting on the figure.
ax = gca
% Make the x and y axes white.
ax.YColor = 'w';
ax.XColor = 'w';
% Set x and y font sizes.
ax.XAxis.FontSize = 20;
ax.YAxis.FontSize = 20;
% Make tick marks go inside.
ax.TickDir = 'in';
% The below would set everything: title, x axis, y axis, and tick mark label font sizes.
% ax.FontSize = 20;
% Bold all labels.
ax.FontWeight = 'bold';
hold off
% Maximize the figure
g = gcf;
g.WindowState = 'maximized';

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by