SigmaPlotter.java

/*
 * Created on 2007/03/30
 * Copyright (C) 2007 Koga Laboratory. All rights reserved.
 *
 */
package org.mklab.tool.control;

import org.mklab.nfc.matrix.DoubleMatrix;
import org.mklab.tool.graph.gnuplot.Canvas;
import org.mklab.tool.graph.gnuplot.Gnuplot;


/**
 * Sigmaプロットを描画するクラスです。
 * 
 * @author koga
 * @version $Revision: 1.3 $, 2007/03/30
 */
public class SigmaPlotter {

  /**
   * Sigmaプロットを描画します。
   * 
   * @param gnuplot Gnuplot
   * @param sigma Sigmaの値
   * @param angularFrequencies 評価する周波数(radian/s)
   */
  public void plot(final Gnuplot gnuplot, final DoubleMatrix sigma, final DoubleMatrix angularFrequencies) {
    plotSigma(gnuplot.getCanvas(), sigma.log10ElementWise(), angularFrequencies);
  }

  /**
   * Sigmaプロット描画します。
   * 
   * @param canvas キャンバス
   * @param sigmas Sigma
   * @param angularFrequencies 評価する周波数(radian/s)
   */
  private void plotSigma(Canvas canvas, DoubleMatrix sigmas, DoubleMatrix angularFrequencies) {
    final double frequencyGridInterval = 10;
    final double frequencyMin = Math.pow(10, Math.floor(Math.log10(angularFrequencies.min().doubleValue())));
    final double frequencyMax = Math.pow(10, Math.ceil(Math.log10(angularFrequencies.max().doubleValue())));

    final double sigmaMin1 = Math.pow(10, Math.floor(Math.log10(sigmas.min().doubleValue())));
    final double sigmaMax1 = Math.pow(10, Math.ceil(Math.log10(sigmas.max().doubleValue())));

    double sigmaGridInterval = Math.ceil(Math.ceil((sigmaMax1 - sigmaMin1)) / 6);
    double sigmaMin = Math.floor(sigmas.min().doubleValue() / sigmaGridInterval) * sigmaGridInterval;
    double sigmaMax = Math.ceil(sigmas.max().doubleValue() / sigmaGridInterval) * sigmaGridInterval;

    sigmaGridInterval = Math.ceil(Math.ceil((sigmaMax - sigmaMin)) / 6);

    canvas.setYLabel("log10(sigma)"); //$NON-NLS-1$
    canvas.setGridVisible(true);
    canvas.setLeftMargin(10);
    canvas.setXRange(frequencyMin, frequencyMax);
    canvas.setXTics(frequencyMin, frequencyGridInterval, frequencyMax);
    canvas.setYRange(sigmaMin, sigmaMax);
    canvas.setYTics(sigmaMin, sigmaGridInterval, sigmaMax);
    canvas.semilogx(angularFrequencies, sigmas, new String[] {"log10(sigma)"}); //$NON-NLS-1$
  }
}