Reputation: 41
I have a problem with MATLAB: I wish to show text in a figure (title of the colorbar) with special characters as index, Greek letter. On the display the index appears in the matrix form (see images), and I dont understand why.
Has somebody already had this problem and can help me please?
I try to create a GUI. So my code is long, but i will try to explain you . I have a variable G_nom wich changes when I call a different greatness : G_nom='{\it\sigma_u}*';
Next a call a function for draw graphic:
%
function figure_exp_num(source,callbackdata)
global Grandeur G g Verticale Horizontale EXP_graphique NUM_graphique M
global M_Int G_Num_Int YI ZI Adim x Q position d S U_debit YCercle ZCercle
global cmin cmax cmin_auto cmax_auto Valeur_perso_colorbar G_map G_nom
global valeur_min_colorbar valeur_max_colorbar f h1 h2 h3 h11 h22 hcb
global y_Num z_Num points_exp points_num Exp_contour Num_contour Exp_contour_1
global Nb_ISO G_nom_indice Titre
%f=figure('units','centimeters','Position',[9 2 25 15],'Visible', 'on','renderer','painters');
clf(f,'reset')
set(f,'Visible','on','Position',[9 2 23 15])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h1=subplot(2,2,1,'Parent',f,'units','centimeters');
assignin('base','h1',h1);
% Variable à tracer
%-------------------------------------------------------------------------
G_map=M_Int(:,:,G);
assignin('base','G_map',G_map);
% Affichage du graphique
%-------------------------------------------------------------------------
h11=pcolor(YI,ZI,G_map);
assignin('base','h11',h11);
% Ajout du Cercle représentant la conduite/ point EXP ou NUM
%--------------------------------------------------------------------------
hold on
plot(YCercle, ZCercle,'k-','LineWidth',4.0); %Tracé du cercle (conduite)
points_exp=plot(M(:,2),M(:,3),'k+','Visible', 'off'); %Tracé des points expérimentaux
[Exp_contour_valeur,Exp_contour]=contour(YI,ZI,G_map,Nb_ISO,'k-',...
'LineWidth', 1.5,'Visible', 'off'); %Courbe iso de la grandeur
hold off
assignin('base','Exp_contour',Exp_contour);
% Caractéristiques du graphique :
%-----------------------------------
% recherche du min et max automatique du graphique
%--------------------------------------------------
[cmin_auto,cmax_auto] = caxis;
assignin('base','cmin_auto',cmin_auto);
assignin('base','cmax_auto',cmax_auto);
cmin=cmin_auto;
cmax=cmax_auto;
assignin('base','cmin',cmin);
assignin('base','cmax',cmax);
% Borne de la colorbar
%------------------------------
caxis([cmin_auto,cmax_auto])
set(valeur_min_colorbar,'string',num2str(cmin_auto,'%.3f'),...
'BackgroundColor',[1 0.5 0]);
set(valeur_max_colorbar,'string',num2str(cmax_auto,'%.3f'),...
'BackgroundColor',[1 0.5 0]);
axis equal; % axes de même longueur
axis([min(YCercle)-0.02 max(YCercle)+0.02 min(ZCercle)-0.02 max(ZCercle)+0.02])
shading(gca,'interp') %lissage de l'interpolation
% Titre du Subplot Expérimentale et des Axes du graphique
%--------------------------------------------------------------------------
title('Exp');
if Adim==1
xlabel ('\ity*');ylabel ('\itz*');
set(gca,'YTick',[-0.5:0.1:0.5])
set(gca,'XTick',[-0.5:0.25:1])
else
xlabel ('y (mm)');ylabel ('z (mm)');
end
h2=subplot(2,2,2,'Parent',f,'units','centimeters');
assignin('base','h2',h2);
%Variable à tracer et GRAPH
%-------------------------------------------------------------------------
h22=pcolor(YI,ZI,G_Num_Int(:,:,g));
assignin('base','h22',h22);
% Ajout du Cercle représentant la conduite/ point EXP ou NUM
%--------------------------------------------------------------------------
hold on
plot(YCercle, ZCercle,'k-','LineWidth',4.0); %Tracé du cercle (conduite)
points_num=plot(y_Num,z_Num,'k+','Visible', 'off'); %Tracé des points numérique
[Num_contour_valeur,Num_contour] = contour(YI,ZI,G_Num_Int(:,:,g),Nb_ISO,'k-','LineWidth', 1.5,'Visible','off'); %Courbe iso de la grandeur
hold off
assignin('base','Num_contour',Num_contour);
% Caractéristiques du graphique
%--------------------------------------------------------------------------
axis equal;
axis([min(YCercle)-0.02 max(YCercle)+0.02 min(ZCercle)-0.02 max(ZCercle)+0.02]);
shading interp;
% min et max de la colorbar du graphique = à celui de l'EXP
%-----------------------------------------------------------
caxis([cmin,cmax])
% Titre du Subplot Expérimentale et des Axes du graphique
%------------------------------------------------------------
title('Num');
if Adim==1
xlabel ('\ity*');ylabel ('\itz*');
set(gca,'YTick',[-0.5:0.1:0.5])
set(gca,'XTick',[-0.5:0.25:1])
else
xlabel ('y (mm)');ylabel ('z (mm)');
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h3=subplot(2,2,[3 4],'Parent',f,'units','centimeters');
assignin('base','h3',h3);
axis off; %N'affiche pas le graphique
caxis([cmin,cmax]) %borne de la colorbar
hcb=colorbar('southoutside'); %Orientation de la colorbar
title(hcb,G_nom); %titre de la colorbar
%ylabel(hcb,G_nom);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Positionnement des subplots dans la fenêtre graphique
%------------------------------------------------------
set(h1,'position',[2,5.5,10,8]) %Position du Subplot1 : Exp
set(h2,'position',[13,5.5,10,8]) %Position du Subplot2 : Num
set(h3,'position',[3,3.2,18.6,5]) %Position du Subplot3 :
end
Upvotes: 4
Views: 119
Reputation: 125874
I've run into this problem a few times myself and switching to software OpenGL rendering as Holt suggests is the typical solution for it. Here's a little more background as to why this is usually the solution...
Figures windows have a 'Renderer'
and 'RendererMode'
property. The 'RendererMode'
property is set by default to 'auto'
, meaning MATLAB will determine the best graphics renderer for the figure based on the complexity of the graphics objects being displayed. For example, if you plot any transparent objects, OpenGL rendering will be used automatically since the other renderer options ('painters'
or 'zbuffer'
) do not support the rendering of transparent objects. NOTE: In older versions of MATLAB the default renderer was 'painters'
, but newer versions appear to use OpenGL rendering by default, and the 'zbuffer'
rendering option has been removed.
Now, OpenGL rendering can be further controlled using the opengl
command. Specifically, you can choose between software or hardware OpenGL rendering. What does this mean? Well, graphics cards often have dedicated on-board hardware that can handle some of the calculations involved in rendering complex graphics, and using this hardware can speed up graphics rendering. However, due to incompatibility issues with your graphics card, graphics drivers, operating system, or MATLAB installation, bugs can sometimes arise like the one you are seeing (with text objects being replicated across the image, which I have personally seen a few times).
The only solution I've found in such a case is to switch to software OpenGL rendering, which may be slightly slower but avoids the bugs arising from incompatible hardware. You could also try updating your graphics drivers, but this never worked for me when I came across this issue (my drivers were already up to date).
In addition, you may want to set things up so that MATLAB always defaults to using software OpenGL in the future. This would require that you either set your preferences using opengl
(only possble in newer versions of MATLAB, I believe) or add the following line to your startup.m
file:
opengl software
Upvotes: 2
Reputation: 37641
This is a common probem I have on Windows when trying to set a colormap
to my plots. I don't know from where this come, but I solve it by doing the following (after the plots):
set(gcf, 'Renderer', 'OpenGL');
opengl software;
Upvotes: 2