Plotting
TimeSeries
defines a recipe that allows plotting to a number of different plotting packages using the Plots.jl framework (no plotting packages will be automatically installed by TimeSeries
).
Here we use the data from Yahoo Fiance as a demo.
using Plots, MarketData, TimeSeries
gr()
ta = yahoo(:GOOG, YahooOpt(period1 = now() - Month(1)))
20×6 TimeArray{Float64, 2, Date, Matrix{Float64}} 2024-04-08 to 2024-05-03
┌────────────┬─────────┬─────────┬─────────┬────────┬──────────┬───────────┐
│ │ Open │ High │ Low │ Close │ AdjClose │ Volume │
├────────────┼─────────┼─────────┼─────────┼────────┼──────────┼───────────┤
│ 2024-04-08 │ 154.015 │ 156.655 │ 153.99 │ 156.14 │ 156.14 │ 1.66415e7 │
│ 2024-04-09 │ 157.35 │ 159.89 │ 156.64 │ 158.14 │ 158.14 │ 2.15381e7 │
│ 2024-04-10 │ 157.88 │ 158.16 │ 156.2 │ 157.66 │ 157.66 │ 1.63392e7 │
│ 2024-04-11 │ 158.34 │ 161.12 │ 157.93 │ 160.79 │ 160.79 │ 1.78417e7 │
│ 2024-04-12 │ 159.405 │ 161.7 │ 158.6 │ 159.19 │ 159.19 │ 1.69682e7 │
│ 2024-04-15 │ 160.28 │ 160.83 │ 156.15 │ 156.33 │ 156.33 │ 2.11409e7 │
│ 2024-04-16 │ 155.64 │ 157.23 │ 155.05 │ 156.0 │ 156.0 │ 1.54132e7 │
│ 2024-04-17 │ 157.19 │ 158.681 │ 156.135 │ 156.88 │ 156.88 │ 1.62378e7 │
│ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │
│ 2024-04-25 │ 153.36 │ 158.28 │ 152.768 │ 157.95 │ 157.95 │ 3.61978e7 │
│ 2024-04-26 │ 175.99 │ 176.42 │ 171.4 │ 173.69 │ 173.69 │ 5.65008e7 │
│ 2024-04-29 │ 170.77 │ 171.38 │ 167.06 │ 167.9 │ 167.9 │ 3.59146e7 │
│ 2024-04-30 │ 167.38 │ 169.87 │ 164.5 │ 164.64 │ 164.64 │ 2.94208e7 │
│ 2024-05-01 │ 166.18 │ 168.81 │ 164.9 │ 165.57 │ 165.57 │ 2.52232e7 │
│ 2024-05-02 │ 166.67 │ 168.53 │ 165.69 │ 168.46 │ 168.46 │ 1.70411e7 │
│ 2024-05-03 │ 169.527 │ 169.85 │ 164.98 │ 169.01 │ 169.01 │ 2.27671e7 │
└────────────┴─────────┴─────────┴─────────┴────────┴──────────┴───────────┘
5 rows omitted
Plotting as multiple series
The recipe allows TimeArray
objects to be passed as input to plot
. The recipe will plot each variable as an individual line, aligning all variables to the same y axis. backend).
plot(ta[:Open, :High, :Low, :Close])
Plotting candlestick
We have seriestype = :candlestick
support that requires four columns exist in the input. They are open
, high
, low
and close
(case-insensitive).
plot(ta, seriestype = :candlestick)
┌ Warning: Keyword argument hover not supported with Plots.GRBackend(). Choose from: annotationcolor, annotationfontfamily, annotationfontsize, annotationhalign, annotationrotation, annotations, annotationvalign, arrow, aspect_ratio, axis, background_color, background_color_inside, background_color_outside, background_color_subplot, bar_width, bins, bottom_margin, camera, clims, color_palette, colorbar, colorbar_entry, colorbar_scale, colorbar_title, colorbar_titlefont, colorbar_titlefontcolor, colorbar_titlefontrotation, colorbar_titlefontsize, connections, contour_labels, discrete_values, fill, fill_z, fillalpha, fillcolor, fillrange, fillstyle, flip, fontfamily, fontfamily_subplot, foreground_color, foreground_color_axis, foreground_color_border, foreground_color_grid, foreground_color_subplot, foreground_color_text, formatter, framestyle, grid, gridalpha, gridlinewidth, gridstyle, group, guide, guidefont, guidefontcolor, guidefontfamily, guidefonthalign, guidefontrotation, guidefontsize, guidefontvalign, html_output_format, inset_subplots, label, layout, left_margin, legend_background_color, legend_column, legend_font, legend_font_color, legend_font_family, legend_font_halign, legend_font_pointsize, legend_font_rotation, legend_font_valign, legend_foreground_color, legend_position, legend_title, legend_title_font_color, legend_title_font_family, legend_title_font_pointsize, legend_title_font_rotation, legend_title_font_valigm, levels, lims, line, line_z, linealpha, linecolor, linestyle, linewidth, link, margin, marker_z, markeralpha, markercolor, markershape, markersize, markerstrokealpha, markerstrokecolor, markerstrokewidth, minorgrid, minorgridalpha, minorgridlinewidth, minorgridstyle, minorticks, mirror, normalize, orientation, overwrite_figure, permute, plot_title, plot_titlefontcolor, plot_titlefontfamily, plot_titlefontrotation, plot_titlefontsize, plot_titlelocation, plot_titlevspan, polar, primary, projection, quiver, ribbon, right_margin, rotation, scale, series_annotations, seriesalpha, seriescolor, seriestype, show, show_empty_bins, showaxis, size, smooth, subplot, subplot_index, thickness_scaling, tick_direction, tickfontcolor, tickfontfamily, tickfonthalign, tickfontrotation, tickfontsize, tickfontvalign, ticks, title, titlefontcolor, titlefontfamily, titlefonthalign, titlefontrotation, titlefontsize, titlefontvalign, top_margin, unitformat, weights, widen, window_title, x, xdiscrete_values, xerror, xflip, xforeground_color_axis, xforeground_color_border, xforeground_color_grid, xforeground_color_text, xformatter, xgrid, xgridalpha, xgridlinewidth, xgridstyle, xguide, xguidefontcolor, xguidefontfamily, xguidefonthalign, xguidefontrotation, xguidefontsize, xguidefontvalign, xlims, xlink, xminorgrid, xminorgridalpha, xminorgridlinewidth, xminorgridstyle, xminorticks, xmirror, xrotation, xscale, xshowaxis, xtick_direction, xtickfontcolor, xtickfontfamily, xtickfonthalign, xtickfontrotation, xtickfontsize, xtickfontvalign, xticks, xunitformat, xwiden, y, ydiscrete_values, yerror, yflip, yforeground_color_axis, yforeground_color_border, yforeground_color_grid, yforeground_color_text, yformatter, ygrid, ygridalpha, ygridlinewidth, ygridstyle, yguide, yguidefontcolor, yguidefontfamily, yguidefonthalign, yguidefontrotation, yguidefontsize, yguidefontvalign, ylims, ylink, yminorgrid, yminorgridalpha, yminorgridlinewidth, yminorgridstyle, yminorticks, ymirror, yrotation, yscale, yshowaxis, ytick_direction, ytickfontcolor, ytickfontfamily, ytickfonthalign, ytickfontrotation, ytickfontsize, ytickfontvalign, yticks, yunitformat, ywiden, z, z_order, zdiscrete_values, zerror, zflip, zforeground_color_axis, zforeground_color_border, zforeground_color_grid, zforeground_color_text, zformatter, zgrid, zgridalpha, zgridlinewidth, zgridstyle, zguide, zguidefontcolor, zguidefontfamily, zguidefonthalign, zguidefontrotation, zguidefontsize, zguidefontvalign, zlims, zlink, zminorgrid, zminorgridalpha, zminorgridlinewidth, zminorgridstyle, zminorticks, zmirror, zrotation, zscale, zshowaxis, ztick_direction, ztickfontcolor, ztickfontfamily, ztickfonthalign, ztickfontrotation, ztickfontsize, ztickfontvalign, zticks, zunitformat, zwiden
└ @ Plots ~/.julia/packages/Plots/ju9dp/src/args.jl:1557
Other available attributes
bar_width::Float64
the valid value is from0
to1
.
plot(ta, seriestype = :candlestick, bar_width = 0.7)
xticks::Int
for controlling the density of x axis labels.
plot(ta, seriestype = :candlestick, xticks = 3, xrotation = 60)