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}} 2025-03-21 to 2025-04-17
┌────────────┬─────────┬─────────┬─────────┬────────┬──────────┬───────────┐
│ │ Open │ High │ Low │ Close │ AdjClose │ Volume │
├────────────┼─────────┼─────────┼─────────┼────────┼──────────┼───────────┤
│ 2025-03-21 │ 163.38 │ 166.47 │ 163.03 │ 166.25 │ 166.25 │ 2.98821e7 │
│ 2025-03-24 │ 169.265 │ 170.5 │ 167.44 │ 169.93 │ 169.93 │ 1.87428e7 │
│ 2025-03-25 │ 171.18 │ 172.91 │ 170.55 │ 172.79 │ 172.79 │ 1.38416e7 │
│ 2025-03-26 │ 171.3 │ 171.94 │ 166.861 │ 167.14 │ 167.14 │ 2.2498e7 │
│ 2025-03-27 │ 166.71 │ 167.44 │ 163.85 │ 164.08 │ 164.08 │ 2.15712e7 │
│ 2025-03-28 │ 162.36 │ 163.81 │ 155.339 │ 156.06 │ 156.06 │ 3.48665e7 │
│ 2025-03-31 │ 154.81 │ 157.13 │ 152.21 │ 156.23 │ 156.23 │ 3.35916e7 │
│ 2025-04-01 │ 155.3 │ 160.08 │ 155.255 │ 158.88 │ 158.88 │ 2.01114e7 │
│ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │
│ 2025-04-09 │ 146.33 │ 161.87 │ 145.81 │ 161.06 │ 161.06 │ 4.64795e7 │
│ 2025-04-10 │ 158.76 │ 160.03 │ 152.2 │ 155.37 │ 155.37 │ 3.52705e7 │
│ 2025-04-11 │ 155.585 │ 159.86 │ 155.585 │ 159.4 │ 159.4 │ 2.2582e7 │
│ 2025-04-14 │ 162.31 │ 164.03 │ 159.92 │ 161.47 │ 161.47 │ 1.82559e7 │
│ 2025-04-15 │ 161.57 │ 162.05 │ 157.645 │ 158.68 │ 158.68 │ 1.56908e7 │
│ 2025-04-16 │ 155.47 │ 158.18 │ 153.91 │ 155.5 │ 155.5 │ 1.69215e7 │
│ 2025-04-17 │ 156.61 │ 157.07 │ 150.9 │ 153.36 │ 153.36 │ 1.95134e7 │
└────────────┴─────────┴─────────┴─────────┴────────┴──────────┴───────────┘
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.
plot(ta[:Open, :High, :Low, :Close])
savefig("multi-series.svg");
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)
savefig("cs.svg");
┌ 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/MR7sb/src/args.jl:1557
Other available attributes
bar_width::Float64
the valid value is from0
to1
.
plot(ta; seriestype=:candlestick, bar_width=0.7)
savefig("bw.svg");
xticks::Int
for controlling the density of x axis labels.
plot(ta; seriestype=:candlestick, xticks=3, xrotation=60)
savefig("xticks.svg");