How can I have a graph with two logarithmic y axes?
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pim Wijnands
el 26 de Oct. de 2017
Comentada: Pim Wijnands
el 26 de Oct. de 2017
I am trying to get a graph with two y variables, both having individual y axes. The y axes and the x-axis should all be logarithmic.
Creating the two y axes using yyaxis seems to work. However, when I try to modify both axes, only the secondary y-axis seems to be in a logarithmic scale. The primary y-axis is linear.
My code:
loglog(f,Gp,'x','MarkerSize',6,'LineWidth',3);
yyaxis left
ylabel('G_{prime} (Pa)')
yyaxis right
ylabel('G_{doubleprime} (Pa)');
hold on
loglog(f,Gdp,'x','MarkerSize',6,'LineWidth',3);
xlabel('Angular Frequency (rad/s)');
set(findall(0,'YAxisLocation','right'),'Yscale','log');
set(findall(0,'YAxisLocation','left'),'Yscale','log');
Attempted solutions:
- I have tried to change both the order and the position of the set(findall(...)) function, but to no avail.
- I have also attempted to solve the problem with plotyy(f,Gp,f,Gdp,@loglog,@loglog). This also did not provide me with the desired result.
- Interchanging the 'loglog' function that creates the plots with 'plot', 'semilogy', or 'semilogx' does not work either.
Some other details:
- Gp, Gdp and f are all 73x1 double.
- Both curves are visible.
- No errors are printed to the console.
Can anyone provide a solution?
0 comentarios
Respuesta aceptada
Walter Roberson
el 26 de Oct. de 2017
My tests show that it is creating a log plot. However, in that range of y values, it is not visibly apparent that the line spacing is log rather than linear. If you compare the plot to semilogx(1:73, log(Gp)) you will see the shape is correct for the loglog plot.
Más respuestas (1)
Steven Lord
el 26 de Oct. de 2017
This code worked fine for me in release R2017b on Windows and showed two Y axes and one X axis, all three in log scale. Try it in your MATLAB session. If it doesn't work for you, use print to create an image from the figure and use the Image button (the one with a green rectangle inside a brown frame) above the comment entry box to include it in your response.
x = 1:10;
y1 = 5*x;
y2 = x.^2;
yyaxis left
h = loglog(x, y1);
yyaxis right
h2 = loglog(x, y2);
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!