how to set y-axis as log scale?
    2.037 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Rohit Bhoi
      
 am 15 Apr. 2016
  
    
    
    
    
    Kommentiert: Mr Thadi
 am 29 Sep. 2024
            I am plotting x-y plot using plot function. I want to set only y-axis as log scale and x-axis as linear? How to do that? I used loglog function but it scales both axis but I want only Y.
0 Kommentare
Akzeptierte Antwort
  Walter Roberson
      
      
 am 22 Sep. 2023
        
      Bearbeitet: MathWorks Support Team
    
 am 22 Sep. 2023
  
      The best way to create that type of axes is to use the semilogy function. Alternatively, you can set the ‘YScale’ property on the axes:
set(gca, 'YScale', 'log')
***Update from Mathworks Support Team - September 2023***
As of R2023b, you can also use the 'yscale ' function. 
23 Kommentare
  Adam Danz
    
      
 am 12 Jul. 2024
				This issue arises because the first bin edge is at x=0 and log(0)=-inf which cannot be represented graphically. 
Assuming there are no data less than or equal to 0 and no bin edges less than 0, you could set the first bin edge according to the smallest value in the data. 
x = rand(1,1000)*10000; 
minPositiveValue = min(x(x>0),[],'all'); 
minbin = 10^floor(log10(minPositiveValue));
ax = axes(); 
h = histogram(ax, x); 
ax.XScale = 'log';
if h.BinEdges(1) == 0
   h.BinEdges(1) = minbin; 
end
Weitere Antworten (2)
  Rohit Sinha
      
 am 27 Apr. 2022
        The easiest way to do this is simply use the following command instead of plot
semilogy(x,y); 
This will plot x axis on a linear scale and y axis on a log scale. Similarly, if you want to plot x axis on log scale and y axis on a linear scale, you can use
semilogx(x,y) ;
2 Kommentare
  Nicholas Santiago
 am 4 Nov. 2022
				yo i totally missed that I generally only read the bold stuff, thanks a ton!
Siehe auch
Kategorien
				Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





















