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

23 vues (au cours des 30 derniers jours)
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:
s=surf(sx,sy,Sweep(i).data(7).WRspice(1:621,:).*1e6)
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 commentaire
Thomas Dixon
Thomas Dixon le 5 Avr 2020
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.

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 5 Avr 2020
Modifié(e) : dpb le 5 Avr 2020
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:
figure
plot(rand(10,1))
hAx=gca;
hAx.XTickLabel(3)={'\color{red}\fontsize{8}\bf 3'};
produces
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 commentaires
dpb
dpb le 5 Avr 2020
"...then after that I will want to adress the XTickLabel(4) and then for arbitrary positioning on the xaxis I wouldn't know which one to adress. However I think I have got round this by adding the ticklabel to the aray then refinding where it is"
I don't see that you have any choice but to somewhere keep track of which tick/tick label you want to address by some lookup or keeping a running pointer to where it is you want to address/modify the label.
It seems you're not modifying the label value from what the tick value is, however, just changing its appearance so you don't need to keep the tick label and search through an arbitrary string to find the numeric value; use the ticks themselves for that. Given the kind of range of values you described above, you might find |ismembertol| useful to find the tick within some value of the wanted value or you could use interp1 to return the nearest, first before, first after, ... depending on how you are choosing which tick it is you want based on the given value you have to set the picking by/with.
Thomas Dixon
Thomas Dixon le 5 Avr 2020
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.

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 5 Avr 2020
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.)
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(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 commentaires
Thomas Dixon
Thomas Dixon le 5 Avr 2020
I don't know why in the first paragraph i asked that question I already know how to do that. I do that like this:
set(gca, 'XTick', unique([9, get(gca, 'XTick')]));
The rest still applies

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by