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-02-20 to 2025-03-19
┌────────────┬─────────┬─────────┬─────────┬────────┬──────────┬───────────┐
│ │ Open │ High │ Low │ Close │ AdjClose │ Volume │
├────────────┼─────────┼─────────┼─────────┼────────┼──────────┼───────────┤
│ 2025-02-20 │ 186.5 │ 187.12 │ 184.6 │ 186.64 │ 186.428 │ 1.20638e7 │
│ 2025-02-21 │ 187.29 │ 187.47 │ 181.13 │ 181.58 │ 181.373 │ 1.95208e7 │
│ 2025-02-24 │ 183.8 │ 185.09 │ 180.88 │ 181.19 │ 180.984 │ 1.8734e7 │
│ 2025-02-25 │ 180.155 │ 180.76 │ 176.77 │ 177.37 │ 177.168 │ 2.08325e7 │
│ 2025-02-26 │ 176.945 │ 178.08 │ 173.59 │ 174.7 │ 174.501 │ 2.36372e7 │
│ 2025-02-27 │ 175.94 │ 176.59 │ 169.752 │ 170.21 │ 170.016 │ 2.59305e7 │
│ 2025-02-28 │ 170.3 │ 172.5 │ 168.39 │ 172.22 │ 172.024 │ 3.00498e7 │
│ 2025-03-03 │ 173.73 │ 175.0 │ 167.64 │ 168.66 │ 168.468 │ 2.4122e7 │
│ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │ ⋮ │
│ 2025-03-11 │ 166.68 │ 168.655 │ 163.24 │ 165.98 │ 165.98 │ 2.37059e7 │
│ 2025-03-12 │ 168.47 │ 169.53 │ 165.48 │ 169.0 │ 169.0 │ 1.98801e7 │
│ 2025-03-13 │ 167.98 │ 168.12 │ 164.07 │ 164.73 │ 164.73 │ 1.52062e7 │
│ 2025-03-14 │ 165.315 │ 168.25 │ 164.51 │ 167.62 │ 167.62 │ 1.86111e7 │
│ 2025-03-17 │ 167.325 │ 168.46 │ 165.81 │ 166.57 │ 166.57 │ 1.78391e7 │
│ 2025-03-18 │ 165.96 │ 166.44 │ 158.8 │ 162.67 │ 162.67 │ 2.46168e7 │
│ 2025-03-19 │ 163.915 │ 168.133 │ 163.05 │ 166.28 │ 166.28 │ 2.49325e7 │
└────────────┴─────────┴─────────┴─────────┴────────┴──────────┴───────────┘
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])
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/3u4B6/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");