Levelsplot line attributes

General forum for EasySpin: questions, how to's, etc.
Post Reply
thanasis
Local Expert
Posts: 242
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Levelsplot line attributes

Post by thanasis »

Hello,

I have a question regarding levelsplot usability: is there any way to get the handles of the plotted lines, so that we can change their colors, thicknesses etc? This in necessary , eg. if we need to overlay different plots on the same figure. As it is documented right now, levelsplot is excellent for understanding the level structure and transitions of a system, but the ability to tweak them would make them much more presentable for publications.

Thanks for considering!
Stefan Stoll
EasySpin Creator
Posts: 1050
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Levelsplot line attributes

Post by Stefan Stoll »

Code: Select all

clear, clc
Sys.g = 2;
levelsplot(Sys,'z',[0 400]);
h = get(gca,'Children')
set(h,'Color','r');
thanasis
Local Expert
Posts: 242
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Levelsplot line attributes

Post by thanasis »

That's it, thanks!
thanasis
Local Expert
Posts: 242
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Levelsplot line attributes

Post by thanasis »

I am resurrecting this thread as I am trying to make a Zeeman plot with custom colors.

While I had managed to make things work with the previous approach, that was a rather special case involving relatively few levels and not many level crossings.

I am now dealing with a system with significantly more levels (512 to be exact, but the problem arises with significantly less).

What happens is that:
-levelsplot generates line segments between crossings (assigned the "level" attribute). When we have many anticrossings, the number of those line segmens may explode.
-In addition, we have line segments for the transition sticks (assigned the "transition" attribute), which may be quite numerous as well, especially when we are dealing with hyperfine interactions.
-Finally, we have the text objects with frequency and orientation.

The get(gca,'Children') command then "catches" all of these objects together (some times so many of them that Matlab may stall) but we cannot know in advance how many of each we will have. So coloring them ex post becomes a tedious trial-and-error process.

I was wondering whether levelsplot could accept a few more arguments (e.g. regarding color and line width) for each of these three types of printed objects, so that it can plot Zeeman diagrams directly with the desired line attributes.

Thanks in advance!

thanasis
Local Expert
Posts: 242
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Levelsplot line attributes

Post by thanasis »

So, I played around and managed to find a partial solution based on the type and tag attributes of the lines and texts.
For anyone with the same issue, the following hack works ex post for two orientations (a more generic version would be needed for an arbitrary number of orientations but I scratched my itch).
I believe it would be more elegant to just plot everything as desired ex ante, if this is easy to implement.

Code: Select all

    h = get(gca,'Children'); % Get ALL objects
    list_types = get(h,'type'); % Get list of types
    list_tags = get(h,'tag');
    % Find text indexes in h
    text_comp = strcmp(list_types,'text'); % Get all types and compare with string 'text'
    text_idx = find(text_comp);
    %     Set indexes for a line with a legend
    legend_idx = text_idx + 1;
    % Find transitions indexes in h
    trans_comp = strcmp(list_tags,'transition'); trans_idx = find(trans_comp);
    % Find levels indexes in h
    level_comp = strcmp(list_tags,'level'); level_idx = find(level_comp);

htext = findobj(gca,'Type','text'); % Get only text
htrans = findobj(gca,'Tag','transition'); % Get only transitions
hlevels = findobj(gca,'Tag','level'); % Get only levels

for j = 1:length(text_idx)
    set(h(text_idx(j)),'Color','w','Linewidth',0.5,'HandleVisibility','off');
end
% Sticks
for jj = trans_idx'
    if jj < text_idx(2)
        set(h(jj),'linestyle','-','Color',blue,'Linewidth',0.5,'HandleVisibility','off'); %%y
    else
        set(h(jj),'linestyle','-','Color',green,'Linewidth',0.5,'HandleVisibility','off'); %z
    end
end
% Levels
for jj = level_idx'
    if jj < text_idx(2)
        set(h(jj),'Color',blue,'Linewidth',0.5,'linestyle','-','HandleVisibility','off'); %y
    else
        set(h(jj),'Color',green,'Linewidth',0.5,'linestyle','-','HandleVisibility','off'); %z
    end
end
for jjj = 1:length(legend_idx)
    set(h(legend_idx(jjj)),'DisplayName',fliplr(Orientations(jjj)),'HandleVisibility','on')
end
Liya12
Newbie
Posts: 1
Joined: Sun May 28, 2023 11:22 pm

Re: Levelsplot line attributes

Post by Liya12 »

Hi Guys, Free Fire Name
The levelsplot line attributes refer to the visual properties of the lines in a levelsplot, which is a type of plot used for visualizing data with contours or discrete levels. These attributes include line color, thickness, style, and transparency, among others.

Post Reply