Opened 4 years ago

Closed 16 months ago

Last modified 16 months ago

#6222 closed defect (fixed)

Very bad vertical axis scale with log Y

Reported by: massimo ceraolo Owned by: Adeel Asghar
Priority: high Milestone:
Component: OMEdit Version: 1.16.0
Keywords: Cc:

Description (last modified by massimo ceraolo)

Consider the enclosed Filter.mo model. Run it and plot Rl.abs_v against time on a linear scale: we see that the span of abs_v is between 0.00026 and 4. When we switch to logY scale therefore we expect the y axis span to be between 10-4 and 101.
Instead, it goes from 1e-100 to 1e-20, which is very bad.

Attachments (3)

Filter.mo (3.3 KB ) - added by massimo ceraolo 4 years ago.
pict1.png (30.3 KB ) - added by massimo ceraolo 3 years ago.
pict2.png (66.4 KB ) - added by massimo ceraolo 3 years ago.

Download all attachments as: .zip

Change History (10)

by massimo ceraolo, 4 years ago

Attachment: Filter.mo added

comment:1 by massimo ceraolo, 4 years ago

Description: modified (diff)

comment:2 by anonymous, 4 years ago

I can confirm this, it was also the case in 1.14.x
Furthermore, the user-settings for min/max value of the log scale are ignored/ lead to display errors

comment:3 by Francesco Casella, 4 years ago

Milestone: 1.17.01.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:4 by Francesco Casella, 3 years ago

Milestone: 1.18.0

Ticket retargeted after milestone closed

comment:5 by massimo ceraolo, 3 years ago

I remember discussing the "difficulty" of creating good log scales, in which I read that even Dymola is not good at this. This discussion was on a different ticket, which I cannot find now.

I want to share here my code that is compact, simple, and works well, as you can see from the pictures pict1.png and pict2.png. I hope it may help to find fast a solution to this ticket.

In the code below I added some additional lines of comment to make it clearer what the data structures contain.

  /* Before this code I must have determined minimum and maximum values of the variable that should be
   *  represented by the axis: minVal and maxVal.   */

  if(myAxis.scaleType!=stLin){  //This is to select casesw iwhen I have decibel o true log scale
    if(maxVal<=0 || minVal<=0){ //minVal and maxVal are minimum and maximum values to be included in axis range
      if(myAxis.type==atX)
        msg="Cannot create a log scale on the x-axis\n"
            "because the range contains null or negative values\n\n"
            "Please change the variable to be plot, or the x-axis range or choose a linear scale";
      else
        msg="Cannot create a log scale on the y-axis\n"
            "because the range contains null or negative values\n\n"
            "Please change the variable to be plot, or the y-axis range or choose a linear scale";
      QMessageBox::critical(this, "MC's PlotXWin",msg,QMessageBox::Ok);
      return 1;
    }

    sprintf(buffer,"%+10.3e",double(minVal));
    sscanf(buffer+7, "%u", &myAxis.eMin);
    sprintf(buffer,"%+10.3e",double(maxVal));
    sscanf(buffer+7, "%u", &aux);
    /* If maxVal is not a power-of-ten, eMax=Aux+1, otherwise eMax=Aux*/
    buffer[6]=0;
    if(strcmp(buffer,"+1.000")==0)
      myAxis.eMax=aux;
    else
      myAxis.eMax=aux+1;
    myAxis.scaleFactor=1.;

    // *** The following two rows are the core of my technique to determine axis extrema ***
    myAxis.scaleMin=powf(10.,myAxis.eMin);
    myAxis.scaleMax=powf(10.,myAxis.eMax);
    // ***
    
    if(myAxis.scaleType==stDB){  //scale in DB: decibels
      sprintf(buffer,"%d",20*myAxis.eMin);
      myAxis.maxTextWidth=myPainter->fontMetrics().width(buffer);
      sprintf(buffer,"%d",20*myAxis.eMax);
      myAxis.maxTextWidth=qMax(myAxis.maxTextWidth, myPainter->fontMetrics().width(buffer));
      sprintf(buffer,"dB");
      if(useBrackets)
        sprintf(buffer,"(dB)");
      myAxis.maxTextWidth=qMax(myAxis.maxTextWidth, myPainter->fontMetrics().width(buffer));
    }else{// myAxis.ScaleType=stLog, and true logarithmic scale
        aux=myPainter->fontMetrics().width("10");
      sprintf(buffer,"%d",myAxis.eMin);
      myPainter->setFont(expFont);
      myAxis.maxTextWidth=aux+myPainter->fontMetrics().width(buffer);
      sprintf(buffer,"%d",myAxis.eMax);
      aux+=myPainter->fontMetrics().width(buffer);
      myAxis.maxTextWidth=qMax(myAxis.maxTextWidth,aux);
      myPainter->setFont(numFont);
    }
  }

by massimo ceraolo, 3 years ago

Attachment: pict1.png added

by massimo ceraolo, 3 years ago

Attachment: pict2.png added

comment:6 by Francesco Casella, 3 years ago

See #7468,

Version 0, edited 3 years ago by Francesco Casella (next)

comment:7 by Adeel Asghar, 16 months ago

Resolution: fixed
Status: newclosed

Fixed with PR #11093

Last edited 16 months ago by Adeel Asghar (previous) (diff)
Note: See TracTickets for help on using tickets.