Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何为域轴和范围轴设置相同的比例JFreeChart_Java_Plot_Jfreechart_Axes - Fatal编程技术网

Java 如何为域轴和范围轴设置相同的比例JFreeChart

Java 如何为域轴和范围轴设置相同的比例JFreeChart,java,plot,jfreechart,axes,Java,Plot,Jfreechart,Axes,我想创建类似的极点/零点图。它用于显示IIR和FIR滤波器特性,如稳定性、类型 我的问题是:如何为两个轴设置相同的比例(而不是范围) 我使用散点图绘制图表 JFreeChart chart = ChartFactory.createScatterPlot("Pole/zero plot", // chart // title "r


我想创建类似的极点/零点图。它用于显示IIR和FIR滤波器特性,如稳定性、类型

我的问题是:如何为两个轴设置相同的比例(而不是范围) 我使用散点图绘制图表

JFreeChart chart = ChartFactory.createScatterPlot("Pole/zero plot", // chart
                                                                        // title
            "real", // x axis label
            "imaginary", // y axis label
            result, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
            );

XYPlot plot = (XYPlot) chart.getPlot();
plot.setDomainGridlinesVisible(true);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);
plot.setDomainGridlinePaint(Color.black);

XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

renderer.setBaseItemLabelsVisible(true);
renderer.setBaseItemLabelsVisible(true, true);


plot.setDomainCrosshairVisible(true);
plot.setDomainCrosshairLockedOnData(true);
plot.setRangeCrosshairVisible(true);
plot.setRangeCrosshairLockedOnData(true);

float dash1[] = { 10.0f };
XYShapeAnnotation unitCircle = new XYShapeAnnotation(
    new Ellipse2D.Double(-1, -1, 2, 2), new BasicStroke(1.0f,
    BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
    dash1, 0.0f), Color.black);
    plot.addAnnotation(unitCircle);
    plot.setBackgroundPaint(Color.white);

chart.setAntiAlias(true);


chartPanel = new JPanel(new BorderLayout());
ChartPanel cp = new ChartPanel(chart);
cp.setMouseWheelEnabled(true);
cp.setToolTipText("test");
cp.setDisplayToolTips(true);
chartPanel.add(cp);
Sans legend,设置
图表面板的首选大小非常有效:

private static final int SIZE = 456;
chartPanel.setPreferredSize(new Dimension(SIZE, SIZE));
关于图表大小,请参见和

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.geom.Ellipse2D;
import java.util.*;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.annotations.XYShapeAnnotation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 * @see http://stackoverflow.com/questions/8048652
 * @see http://stackoverflow.com/questions/7231824
 * @see http://stackoverflow.com/questions/7205742
 * @see http://stackoverflow.com/questions/7208657
 * @see http://stackoverflow.com/questions/7071057
 */
public class ScatterAdd extends JFrame {

    private static final int N = 8;
    private static final int SIZE = 456;
    private static final String title = "Scatter Add Demo";
    private static final Random rand = new Random();
    private XYSeries added = new XYSeries("Added");

    public ScatterAdd(String s) {
        super(s);
        final ChartPanel chartPanel = createDemoPanel();
        chartPanel.setPreferredSize(new Dimension(SIZE, SIZE));
        this.add(chartPanel, BorderLayout.CENTER);
        JPanel control = new JPanel();
        control.add(new JButton(new AbstractAction("Add") {

            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i < N; i++) {
                    added.add(rand.nextGaussian(), rand.nextGaussian());
                }
            }
        }));
        this.add(control, BorderLayout.SOUTH);
    }

    private ChartPanel createDemoPanel() {
        JFreeChart jfreechart = ChartFactory.createScatterPlot(
            title, "X", "Y", createSampleData(),
            PlotOrientation.VERTICAL, false, true, false);
        XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
        xyPlot.setDomainCrosshairVisible(true);
        xyPlot.setRangeCrosshairVisible(true);
        XYItemRenderer renderer = xyPlot.getRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        adjustAxis((NumberAxis) xyPlot.getDomainAxis(), true);
        adjustAxis((NumberAxis) xyPlot.getRangeAxis(), false);
        XYShapeAnnotation unitCircle = new XYShapeAnnotation(
            new Ellipse2D.Double(-1, -1, 2, 2), new BasicStroke(1.0f,
            BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f), Color.black);
        xyPlot.addAnnotation(unitCircle);
        xyPlot.setBackgroundPaint(Color.white);

        return new ChartPanel(jfreechart);
    }

    private void adjustAxis(NumberAxis axis, boolean vertical) {
        axis.setRange(-1.0, 1.0);
        axis.setTickUnit(new NumberTickUnit(0.5));
        axis.setVerticalTickLabels(vertical);
    }

    private XYDataset createSampleData() {
        XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
        XYSeries series = new XYSeries("Random");
        for (int i = 0; i < N * N; i++) {
            series.add(rand.nextGaussian(), rand.nextGaussian());
        }
        xySeriesCollection.addSeries(series);
        xySeriesCollection.addSeries(added);
        return xySeriesCollection;
    }

    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                ScatterAdd demo = new ScatterAdd(title);
                demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                demo.pack();
                demo.setLocationRelativeTo(null);
                demo.setVisible(true);
            }
        });
    }
}

import java.awt.BasicStroke;
导入java.awt.BorderLayout;
导入java.awt.Color;
导入java.awt.Dimension;
导入java.awt.EventQueue;
导入java.awt.event.ActionEvent;
导入java.awt.geom.Ellipse2D;
导入java.util.*;
导入javax.swing.AbstractAction;
导入javax.swing.JButton;
导入javax.swing.JFrame;
导入javax.swing.JPanel;
导入org.jfree.chart.*;
导入org.jfree.chart.annotations.xyshapeanotation;
导入org.jfree.chart.axis.NumberAxis;
导入org.jfree.chart.axis.NumberTickUnit;
导入org.jfree.chart.plot.PlotOrientation;
导入org.jfree.chart.plot.XYPlot;
导入org.jfree.chart.renderer.xy.XYItemRenderer;
导入org.jfree.data.xy.XYDataset;
导入org.jfree.data.xy.XYSeries;
导入org.jfree.data.xy.XYSeriesCollection;
/**
*@见http://stackoverflow.com/questions/8048652
*@见http://stackoverflow.com/questions/7231824
*@见http://stackoverflow.com/questions/7205742
*@见http://stackoverflow.com/questions/7208657
*@见http://stackoverflow.com/questions/7071057
*/
公共类ScatterAdd扩展JFrame{
专用静态最终整数N=8;
私有静态最终整数大小=456;
私有静态最终字符串title=“散布添加演示”;
私有静态最终随机兰德=新随机();
添加的专用XYSeries=新的XYSeries(“添加”);
公共散点添加(字符串s){
超级(s);
最终ChartPanel ChartPanel=createDemoPanel();
chartPanel.setPreferredSize(新尺寸(尺寸,尺寸));
添加(chartPanel,BorderLayout.CENTER);
JPanel控件=新的JPanel();
add(新的JButton(新的抽象操作(“add”){
@凌驾
已执行的公共无效操作(操作事件e){
对于(int i=0;i
Sans legend,设置图表面板的首选大小非常有效:

private static final int SIZE = 456;
chartPanel.setPreferredSize(new Dimension(SIZE, SIZE));
关于图表大小,请参见和

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.geom.Ellipse2D;
import java.util.*;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.annotations.XYShapeAnnotation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

/**
 * @see http://stackoverflow.com/questions/8048652
 * @see http://stackoverflow.com/questions/7231824
 * @see http://stackoverflow.com/questions/7205742
 * @see http://stackoverflow.com/questions/7208657
 * @see http://stackoverflow.com/questions/7071057
 */
public class ScatterAdd extends JFrame {

    private static final int N = 8;
    private static final int SIZE = 456;
    private static final String title = "Scatter Add Demo";
    private static final Random rand = new Random();
    private XYSeries added = new XYSeries("Added");

    public ScatterAdd(String s) {
        super(s);
        final ChartPanel chartPanel = createDemoPanel();
        chartPanel.setPreferredSize(new Dimension(SIZE, SIZE));
        this.add(chartPanel, BorderLayout.CENTER);
        JPanel control = new JPanel();
        control.add(new JButton(new AbstractAction("Add") {

            @Override
            public void actionPerformed(ActionEvent e) {
                for (int i = 0; i < N; i++) {
                    added.add(rand.nextGaussian(), rand.nextGaussian());
                }
            }
        }));
        this.add(control, BorderLayout.SOUTH);
    }

    private ChartPanel createDemoPanel() {
        JFreeChart jfreechart = ChartFactory.createScatterPlot(
            title, "X", "Y", createSampleData(),
            PlotOrientation.VERTICAL, false, true, false);
        XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
        xyPlot.setDomainCrosshairVisible(true);
        xyPlot.setRangeCrosshairVisible(true);
        XYItemRenderer renderer = xyPlot.getRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        adjustAxis((NumberAxis) xyPlot.getDomainAxis(), true);
        adjustAxis((NumberAxis) xyPlot.getRangeAxis(), false);
        XYShapeAnnotation unitCircle = new XYShapeAnnotation(
            new Ellipse2D.Double(-1, -1, 2, 2), new BasicStroke(1.0f,
            BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f), Color.black);
        xyPlot.addAnnotation(unitCircle);
        xyPlot.setBackgroundPaint(Color.white);

        return new ChartPanel(jfreechart);
    }

    private void adjustAxis(NumberAxis axis, boolean vertical) {
        axis.setRange(-1.0, 1.0);
        axis.setTickUnit(new NumberTickUnit(0.5));
        axis.setVerticalTickLabels(vertical);
    }

    private XYDataset createSampleData() {
        XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
        XYSeries series = new XYSeries("Random");
        for (int i = 0; i < N * N; i++) {
            series.add(rand.nextGaussian(), rand.nextGaussian());
        }
        xySeriesCollection.addSeries(series);
        xySeriesCollection.addSeries(added);
        return xySeriesCollection;
    }

    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                ScatterAdd demo = new ScatterAdd(title);
                demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                demo.pack();
                demo.setLocationRelativeTo(null);
                demo.setVisible(true);
            }
        });
    }
}

import java.awt.BasicStroke;
导入java.awt.BorderLayout;
导入java.awt.Color;
导入java.awt.Dimension;
导入java.awt.EventQueue;
导入java.awt.event.ActionEvent;
导入java.awt.geom.Ellipse2D;
导入java.util.*;
导入javax.swing.AbstractAction;
导入javax.swing.JButton;
导入javax.swing.JFrame;
导入javax.swing.JPanel;
导入org.jfree.chart.*;
导入org.jfree.chart.annotations.xyshapeanotation;
导入org.jfree.chart.axis.NumberAxis;
导入org.jfree.chart.axis.NumberTickUnit;
导入org.jfree.chart.plot.PlotOrientation;
导入org.jfree.chart.plot.XYPlot;
导入org.jfree.chart.renderer.xy.XYItemRenderer;
导入org.jfree.data.xy.XYDataset;
导入org.jfree.data.xy.XYSeries;
导入org.jfree.data.xy.XYSeriesCollection;
/**
*@见http://stackoverflow.com/questions/8048652
*@见http://stackoverflow.com/questions/7231824
*@见http://stackoverflow.com/questions/7205742
*@见http://stackoverflow.com/questions/7208657
*@见http://stackoverflow.com/questions/7071057
*/
公共类ScatterAdd扩展JFrame{
专用静态最终整数N=8;
私有静态最终整数大小=456;
私有静态最终字符串title=“散布添加演示”;
私有静态最终随机兰德=新随机();
添加的专用XYSeries=新的XYSeries(“添加”);
公共散点添加(字符串s){
超级(s);
最终ChartPanel ChartPanel=createDemoPanel();
chartPanel.setPreferredSize(新尺寸