Minimal-code to get axes limits of log-log plots, but using gscatter
조회 수: 9(최근 30일)
표시 이전 댓글
I used to specify scatter plots using loglog(X,Y,'o') to plot little circles at the data points. Now, gscatter(X,Y,GroupVector,'br','o') allows me to designate different colours for different data points. In my case, I only had two groups, and with logical GroupVector above designating which points belongs to which group. The 'br' says to use blue and red for the two groups.
Unfortunately, gscatter doesn't have a log scale option. I can set(gca,'xscale','log','yscale','log'), but I get complaints that negative axis limits are ignored. Sure enough, that is because the axis limits do include negative numbers, even if the data does not. As a result of this, the log scale scatter plot does not *automatically* have the nice axis limits that loglog(X,Y,'o') has.
My nonideal solution has been to create both plots, then copy the axes limits from the loglog plot to the gscatter plot. It seems heavily redundant. It sure would be nice to have a log scale option for gscatter. In the meantime, what is the most minimal code alternative of replicating loglog axes limits for gscatter? My method *might* be "minimal code", but I mean without duplicating plots.
댓글 수: 0
답변(3개)
Fabio Freschi
2022년 6월 2일
You can remove the negative part of the axis before setting the log scale
set(gca,'XLim',[0 max(xlim)],'YLim',[0 max(ylim)]);
set(gca,'XScale','log','YScale','log')
댓글 수: 3
Fabio Freschi
2022년 6월 2일
편집: Fabio Freschi
2022년 6월 2일
Is this working for you
set(gca,'XLim',[10^floor(log10(max([min(xlim) 0]))) 10^ceil(log10(max(xlim)))],'YLim',[10^floor(log10(max([min(ylim) 0]))) 10^ceil(log10(max(ylim)))]);
set(gca,'XScale','log','YScale','log')
참고 항목
범주
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!