Hi. I have a long time series comprising 238 quarterly observations (1960.Q1-2019.Q2)). I want to produce a simple time series plot using PlotlyJS.jl
to benefit from interactivity. However, I have a problem with the x-axis displaying the correct information. For example, if I define the quarterly observations simply as:
period4 = LinRange(1960,2019.25,238)
I get the plot below with the following code:
trace10 = scatter(;x = period4, y = quarter_data[:,2], name = "GDP", line_color = "Blue")
trace11 = scatter(;x = period4, y = quarter_data[:,3], name = "CONS", line_color = "Red")
trace12 = scatter(;x = period4, y = quarter_data[:,4], name = "INV", line_color = "Gray")
layout = Layout(;title = "Some Macroeconomic Aggregates: USA (1960-Q1--2019-Q2)",
xaxis_title = "Quarterly obervations",
xaxis_range = [1960, 2020],
yaxis_title = "Bilions of US dollars",
#yaxis_range=[-2, 2],
titlefont_size = 16)
p10 = plot([trace10 , trace11, trace12], layout)
The problem with this plot is: how do I get rid of the thousands-comma separator in the x-axis? Apart from this problem, everything else looks perfect in the plot. As a date, 2004.25 looks acceptable, but 2,004.25 looks awkward.
If instead, for the same data I use Dates.jl
and MontlyDates.jl
, the quarterly observations will be defined as:
using Dates
using MonthlyDates
period5 = QuarterlyDate("1960-Q1") : Quarter(1) : QuarterlyDate("2019-Q2")
and the following code will produce the plot below:
trace13 = scatter(;x = period5, y = quarter_data[:,6], name = "FFR", line_color = "Blue")
trace14 = scatter(;x = period5, y = quarter_data[:,7], name = "UN", line_color = "Red")
layout = Layout(;title = "Some Macroeconomic Aggregates: USA (1960-Q1--2019-Q2)",
#xaxis: {
#tickmode= "array",
#tickvals = [1, 80, 160, 240],
#ticktext = ['1960-Q1', '1980-Q1', '2000-Q1', '2020-Q1']
# },
xaxis_title = "Quarterly obervations",
#xaxis_range = [1960, 2020],
yaxis_title = "Percentage points",
#yaxis_range=[-2, 2],
titlefont_size = 16)
p10 = plot([trace13 , trace14], layout)
The x-axis of this plot turns it useless. How do I format the x-ticks such that I can remove the mess with the dates from that plot?
I tried the docs in PlotylyJS and found nothing about formatting xticks
. In Plotly.js I found useful information but, apparently, it cannot just be copy+past into PlotlyJS. Help will be appreciated. Thanks.