Is it possible to add an axes toolbar button to the default axes toolbar?

3 vues (au cours des 30 derniers jours)
Hello,
I've made a toolbar button to help with some of my data analysis. Is it possible for me to add code to my startup.m file to include this button on all default axtoolbar objects that I create, or do I have to create it manually every time?
I like this functionality, but I don't see myself manually creating the button for every plot that I make. I've also used
set(groot,'defaultFigureWindowButtonDownFcn',@highlightOnButtonDown);
to do something similar, but I really like the ability to turn the functionality on and off via the axtoolbar.
For example, the following code creates the below image:
plot(rand(5));
ax = gca;
tb = axtoolbar(ax,{'zoomin','zoomout','restoreview'});
btn = axtoolbarbtn(tb,'state');
btn.Icon = 'highlight_icon.png';
btn.Tooltip = 'Highlight Lines';
btn.ValueChangedFcn = @highlightToggle;
  2 commentaires
Mario Malic
Mario Malic le 13 Fév 2023
I have never tried it, but maybe CreateFcn argument supplied to axes might do the trick.
Alexander Halbleib
Alexander Halbleib le 13 Fév 2023
@Mario Malic ah! That was a brilliant idea! Unfortunately, I saw "Modifying the default axes toolbar is not supported" when I implemented it. I'm going to play around with it a little though, and see if I can figure out a workaround.
Thank you!

Connectez-vous pour commenter.

Réponse acceptée

Alexander Halbleib
Alexander Halbleib le 13 Fév 2023
@Mario Malic provided a quick solution! I was able to place this line in my startup.m file:
set(groot,'defaultAxesCreateFcn',@createHighlightToggle);
This is the the function createHighlightToggle():
function createHighlightToggle(src,~)
%CREATEHIGHLIGHTTOGGLE Add the "Highlight Lines" button to the axes toolbar
tb = axtoolbar(src,'default');
btn = axtoolbarbtn(tb,'state');
btn.Icon = 'highlight_icon.png';
btn.Tooltip = 'Highlight Lines';
btn.ValueChangedFcn = @highlightToggle;
end
That works! The only caveat is that I need to set hold to "on" or "all" - otherwise the new button toolbar is immediately overwritten with the first plotted object.
  2 commentaires
Mario Malic
Mario Malic le 13 Fév 2023
Within createHighlightToggle you can probably put
hold(src, 'on');
Alexander Halbleib
Alexander Halbleib le 13 Fév 2023
Yeah, it works like a charm! Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by