How do I change the appearance of a tick label over a number of iterative values through a pre-exisitng tick label?

18 ビュー (過去 30 日間)
I have a plot which updates to create a video file. It plots a sweeping signal from 1-11GHz. I want to add the label of the signal to the yaxis (surface plot) at each point so i use
set(gca, 'YTick', unique([Sweep(i).Sig_Freq, get(gca, 'YTick')]));
Sweep(i) is each point in the sweep and its Sig_Freq field is the frequency of the signal. As you can imagine Sweep(i).data is anothe field which contains the corresponding data and I plot with:
I then updata the ticks to give me the signal uniquely with
set(gca, 'YTick', unique([Sweep(i).Sig_Freq, get(gca, 'YTick')]));
I first would like to be ablet to adjust the signal label for example smaller font size and maybe red in colour so for all frequencies 1-10 maybe i can set yticklabel(2) to do that. But then how do i update that when yticklabel(2) is the 10GHz tick and the signal has swept over 10-11. I understand I could achieve this semi-manually by just uting a for sig_Freq<10 ....... then something else but i may want to change this for multiple different purposes and zoom in on plot thus changing the yticklabels etc..
An idea I had for what I would like is a perhaps some clever way of labelling this specific label so that at the point I add it to the ytick labels it has a label then I can always adress this partricular tick bsaed on its label or someting like that. Is this possible? and if so how?
What I want to achieve is a way to programtically add a specific ytick and yticklabel to a plot, then move this tick and label with subsequent updated plots through a pre-existing static ylabel and format this individual added yticklabel appearance for each plot without prior knoweldge of exactly where the static ylabel is. My current code looks like this and I am trying to load the Sweep structure but it is too large and I will look to make a reasonable MWE in the near future.
  1 件のコメント
Thomas Dixon
Thomas Dixon 2020 年 4 月 5 日
I have answered part of this question myself. I can find where the number is in the lsit of Yticks by simply using
fs_i = find(ax.YTick==Sweep(i).Sig_Freq);
ax.YTickLabel(fs_i) = {[]};
This finds the signal frequnecy in the list of frequency labels on my plot and deletes it.
Unfortunately i cant do much else with it. really I would like to extend the tick marker for it make the tick marker red and the font and change the font style or something similar.



dpb 2020 年 4 月 5 日
編集済み: dpb 2020 年 4 月 5 日
Think you can do what you want or at least a reasonable facsimile thereof w/ basic 'TeX' interpreter -- 'LaTeX' is such a pain to deal with I'd not mess with it unless run into a real show-stopper without.
But, as far as the size, color, etc., see the document for TeX Markup in the documentation for at the link for 'Interpreter' in text function documentation. All that works for tick labels on a tick-by-tick value in the X/YTickLabel array
Just as a trivial example:
hAx.XTickLabel(3)={'\color{red}\fontsize{8}\bf 3'};
where one sees the third tick label red and smaller fontsize and bolded in comparison to the default for the other. This is w/ defatul TeX interpreter.
As far as the thing about keeping some static label, I don't fully comprehend the intent or effect, but I'd guess what you may want there would be a text object with its specific handle to refer to as the static object instead of a tick label (which is just an element of an array on a 1:1 correspondence to the ticks for a given axis). But, as the above shows, you can do all kinds of effects thingies on those individually by setting the desired properties as interpreted text strings for any element of the array--and as the way it is effected above shows, that's dynamically adjustable simply by writing the desired array location.
BTW, retrieve and then use the specific axis handle instead of sprinkling calls to gca all over the code -- that ensures you're always programmatically addressing the axis which is the intended target instead of one the user may have brought into focus.
  4 件のコメント
Thomas Dixon
Thomas Dixon 2020 年 4 月 5 日
Thank you both for the very comprehensive answers. I have accepted dpb's answer however note that ImageAnalyst gives a lot of detail in and fully worked example for many plot modifications.


その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 4 月 5 日
See attached demo that shows you how to control appearance of lots of things on an axes control.
% Demo to make a black graph with red Y axis, green X axis, and yellow grid.
% Initialization steps:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
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(X, Y, 'gs-', 'LineWidth', 2, 'MarkerSize', 10);
grid on;
title('Y vs. X', 'FontSize', 12);
% Make labels for the two axes.
xlabel('X Axis');
ylabel('Y axis');
% 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
  3 件のコメント



Help Center および File ExchangeAxis Labels についてさらに検索


Community Treasure Hunt

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

Start Hunting!

Translated by