0

I'm trying to draw polyline which tracking several dots(timeseries) in quadrants. Since dots are multiple, what I imagine is that line itself has color property that signals the trajectory of the dots, like light red to rgb(255,0,0)

My reproducible data is like the following timeseries x and y cordinates

         x y
 2017-01 2.8 2.3
 2017-02 -3.2 0.2
 2017-03 2.1 1.4
 2017-04 -1.9 0.0
 2017-05 1.3 0.7
 2017-06 -1.1 -0.1
 2017-07 1.1 0.5
 2017-08 -0.2 0.2
 2017-09 0.3 0.3
 2018-10 0.5 0.5
 2017-11 -1.3 -0.3
 2017-12 -2.1 -1.7

And here attach is a graph I do manually in excel, though I want line to be gradient color to utmost.

enter image description here

cf) I doesn't matter the language you suggest. Matlab, R, Python, Java, C++, Javascript...anything is welcome as long as I can reproduce code in my computer... Thank you very much for your help.

import java.awt.*;

import java.awt.font.FontRenderContext;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Path2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ImageObserver;
import java.awt.image.RenderedImage;
import java.awt.image.renderable.RenderableImage;
import java.io.*;
import java.text.AttributedCharacterIterator;
import java.util.Map;

public class Main {

    public static void main(String[] args) throws IOException {
        //System.out.println("Hello World!");
        Graphics2D graphics = new Graphics2D() {...
}
        double[] x = {2.8, -3.2};
        double[] y = {2.3, 0.2};
        Path2D polyline = new Path2D.Double();
        polyline.moveTo(x[0], y[0]);
        for (int i=1; i<x.length; i++){
        polyline.lineTo(x[i], y[i]);
        }
        graphics.draw(polyline);
    }
}
Hannah Lee
  • 383
  • 2
  • 7
  • 19

0 Answers0