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)))
17×6 TimeArray{Float64, 2, Date, Matrix{Float64}} 2024-12-23 to 2025-01-17
┌────────────┬─────────┬────────┬─────────┬────────┬──────────┬───────────┐
│ │ Open │ High │ Low │ Close │ AdjClose │ Volume │
├────────────┼─────────┼────────┼─────────┼────────┼──────────┼───────────┤
│ 2024-12-23 │ 194.03 │ 196.49 │ 191.63 │ 195.99 │ 195.99 │ 1.52359e7 │
│ 2024-12-24 │ 196.17 │ 197.67 │ 195.198 │ 197.57 │ 197.57 │ 6.8098e6 │
│ 2024-12-26 │ 196.74 │ 198.16 │ 195.87 │ 197.1 │ 197.1 │ 7.9079e6 │
│ 2024-12-27 │ 196.47 │ 196.8 │ 191.972 │ 194.04 │ 194.04 │ 1.4693e7 │
│ 2024-12-30 │ 190.865 │ 193.78 │ 190.36 │ 192.69 │ 192.69 │ 1.22095e7 │
│ 2024-12-31 │ 192.445 │ 193.25 │ 189.58 │ 190.44 │ 190.44 │ 1.43552e7 │
│ 2025-01-02 │ 191.485 │ 193.2 │ 188.71 │ 190.63 │ 190.63 │ 1.75452e7 │
│ 2025-01-03 │ 192.725 │ 194.5 │ 191.35 │ 193.13 │ 193.13 │ 1.2875e7 │
│ 2025-01-06 │ 195.15 │ 199.56 │ 195.06 │ 197.96 │ 197.96 │ 1.94833e7 │
│ 2025-01-07 │ 198.27 │ 202.14 │ 195.94 │ 196.71 │ 196.71 │ 1.69668e7 │
│ 2025-01-08 │ 193.95 │ 197.64 │ 193.75 │ 195.39 │ 195.39 │ 1.43353e7 │
│ 2025-01-10 │ 195.42 │ 197.62 │ 191.6 │ 193.17 │ 193.17 │ 2.07538e7 │
│ 2025-01-13 │ 191.35 │ 192.49 │ 188.66 │ 192.29 │ 192.29 │ 1.31691e7 │
│ 2025-01-14 │ 192.5 │ 193.27 │ 189.64 │ 191.05 │ 191.05 │ 1.36512e7 │
│ 2025-01-15 │ 194.35 │ 197.8 │ 193.33 │ 196.98 │ 196.98 │ 1.28949e7 │
│ 2025-01-16 │ 195.825 │ 196.98 │ 194.3 │ 194.41 │ 194.41 │ 1.34496e7 │
│ 2025-01-17 │ 198.05 │ 198.81 │ 195.31 │ 197.55 │ 197.55 │ 2.19778e7 │
└────────────┴─────────┴────────┴─────────┴────────┴──────────┴───────────┘
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/Ec1L1/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");