How to make QtChart do not draw line chart at certaing ranges? - qt

The code below draws line from year 2020 to 2023 that passes through the year 2022. The point is, how to make QChartView to ignore the year 2022, i.e. draw line from 2021 immediately to 2023, or saying in another words, remove 2022 from X axis?
auto series = new QLineSeries();
series->append(QDateTime(QDate(2020, 1, 1)), 100);
series->append(QDateTime(QDate(2021, 1, 1)), 200);
series->append(QDateTime(QDate(2023, 1, 1)), 300);
series->append(QDateTime(QDate(2023, 1, 1)), 200);
QDateTimeAxis *axisX = new QDateTimeAxis;
axisX->setTickCount(20);
axisX->setLabelsAngle(-90);
axisX->setFormat("dd.MM.yyyy hh:mm:ss");
chart->addAxis(axisX, Qt::AlignBottom);
series->attachAxis(axisX);
QValueAxis *axisY = new QValueAxis;
axisY->setTickCount(30);
chart->addAxis(axisY, Qt::AlignLeft);
series->attachAxis(axisY);
chart->setTitle(m_stock->name());
m_chart_view->setChart(chart);

Finally solution is found. Should use QBarCategoryAxis instead of QDateTimeAxis.

Related

offset lexis grid by one

I have a dataset that has age cohorts from 0 - 80, and years 1900-2021. I am making a lexis plot with this data using the lexis_grid function from the LexisPlotR package. I am using the following code to get started:
library(LexisPlotR)
lexis_grid(year_start = 1900,
year_end = 2021,
age_start = 0,
age_end = 80,
delta = 10
)
However, what this does is sets the upper righthand end of the diaganal lines at 2021, and so they don't like up with vertical decade lines and it just looks wrong:
Any advice on how to index the diagonal lines to start at 1900, rather than end at 2021?
Change year_end to 2020 or 2030, so it increments in 10s to match with age increment - delta:
lexis_grid(year_start = 1900,
year_end = 2030,
age_start = 0,
age_end = 80,
delta = 10)

Heatmap with calendR

Newbie here, I am having an issue creating a heatmap with the following data (365 variables)
The error is:
"Error in calendR(year = 2021, special.days = Events11, gradient = TRUE, :
No element of the 'special.days' vector can be greater than the number of days of the corresponding month or year"
The only time it seems to work is when "special.days = 1:365" for some reason, can anyone help?
Events11 <- c(879,1997,2122,2767,3334,3425,3373,3353,4352,2882,2964,3686,3922,3152,3536,2819,2110,3101,2687,2290,3678,2658,3004,2586,2586,1089,1922,2254,2769,1844,368,1516,1973,2292,1430,1064,663,521,844,1176,1112,1163,1544,582,459,312,221,494,645,782,907,737,1275,2485,2821,2829,3515,6612,3022,3010,3647,5073,3579,4840,6149,5813,8150,9511,6704,6938,6499,11675,4833,1952,3797,3342,3275,5974,11779,15132,10208,4661,7376,5427,5538,11605,6663,8053,8828,5658,4812,8217,17934,15919,10248,15543,14057,4645,11047,4764,9813,9884,8937,7373,7613,9728,12547,11891,5883,5561,5671,9492,11812,13328,7717,12754,16214,5780,8443,10576,21690,22206,8531,7884,10692,8006,11233,12929,6071,7876,9380,11428,14119,17265,13049,20364,12795,10549,13406,17304,20889,30104,18677,16910,15846,17105,9676,5682,18111,22761,18455,16354,17081,19631,21521,30320,24527,14793,18815,20676,21281,24869,28841,29919,19366,20332,21539,21771,23542,31261,18387,17988,20929,19720,12373,13415,11694,24158,13381,14631,15659,20661,22326,28036,28086,23317,19473,19109,19031,24713,20944,10558,16633,19040,21134,17094,19541,31877,27352,19866,21586,21290,21986,21712,27321,26976,20321,21349,22253,22841,24917,30966,25601,19443,20559,21065,21927,22585,30466,23038,14026,17085,17844,20310,24250,32693,26920,19540,20916,21128,21063,23518,26588,25821,19457,14416,16899,21696,22544,25713,19766,18540,18968,20954,20616,19491,23345,28157,24786,15904,20167,20770,22116,28073,22788,17766,19359,20847,22395,21727,27347,23476,15968,14458,13638,16652,19825,24884,21715,17256,18275,19135,19228,21720,19814,15708,14377,16425,16943,13247,16907,27027,25335,10716,15976,14720,16662,16007,20841,19649,16428,18308,17843,13039,14957,17318,3700,6407,13638,14054,7826,4673,14996,12711,10619,10775,10815,10800,11542,13998,13985,12741,12248,12649,8324,6884,7688,4925,7070,10035,8261,7648,8192,9358,7975,6196,6926,6387,2785,3155,4468,4491,6375,8552,8766,10617,9641,8539,3107,5466,5286,6626,7755,5675,5902,6524,7365,8356,9047,6872,6544,4375,4227,5613,5041,3697,4320,3224,2266,2733,3521,2042,3931,4604,4689)
calendR(year = 2021,
special.days = Events11,
gradient = TRUE,
special.col = rgb(1, 0, 0, alpha = 0.6),
low.col = "white")
"Error in calendR(year = 2021, special.days = Events11, gradient = TRUE, :
No element of the 'special.days' vector can be greater than the number of days of the corresponding month or year"
This is due to the way calendR do with scale - they restricted the values of element to no greater than 365. What you can do is normalize the input to a scale that in acceptable range no greater than 365 for a year or 3x days for a month.
Here is an example
library(calendR)
# a scale function that always have the value between 0 - 1
scale_fn <- function(x) { x / sqrt(sum(x^2)) }
# normalized your data
Events11_normalized <- scale_fn(Events11)
calendR(year = 2021,
special.days = Events11_normalized,
gradient = TRUE,
special.col = rgb(1, 0, 0, alpha = 0.6),
low.col = "white")
And here the calendR work just fine.
Created on 2022-01-26 by the reprex package (v2.0.1)

RangeSlider does not work with scatter plot

Is it possible to make the range slider work with a scatter plot? The slider works if I change the scatter to a line plot but that does not work for me as I can not use the box select tool with line plots. The snippet below is simplified to demonstrate the issue. I suspect the embedded JavaScript is the issue but I may be wrong as it works just fine with a line plot. Thanks.
from bokeh.io import show
from bokeh.models import CustomJS, RangeSlider, Column, Row
from bokeh.plotting import figure
x = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
y = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
scatter_plot = figure(width=250, plot_height=600)
scatter_plot.scatter(x, y)
callback = CustomJS(args=dict(y_range=scatter_plot.y_range), code="""
var start = cb_obj.value
y_range.start = start[0]
y_range.end = start[1]
""")
depth_slider = RangeSlider(width=250, show_value=False, start=-20, end=120, value=(20, 80), step=20,
title="Y Scale")
depth_slider.js_on_change('value', callback)
layout = Column(Row(depth_slider), scatter_plot, )
show(layout)
There seems to be some race condition going on or a discrepancy between how Python and JS version of Bokeh work.
By default, all ranges are instances of DataRange1d class which recompute start and end when needed. In this case, it for some reason recomputes the values after you set them manually.
To fix it, specify the range manually from the get go:
scatter_plot = figure(..., y_range=(20, 80))

Boundary constrain leads to internal loop, what happens here and why?

My Script ceases to work for my easy conduction problem. Could somebody explain to me why the following line of code T.faceValue.constrain(alp/lam*(Tu-T.faceValue),where=mesh.exteriorFaces) # Boundary Condition for Solver results in fipy giving up on me?
Full Code:
cv=900.
lam=5.
alp=300.
T0 = 25.
Tu = 400.
cellSize = 0.05
radius = 1.
mesh = Gmsh2D('''
cellSize = %(cellSize)g;
radius = %(radius)g;
Point(1) = {0, 0, 0, cellSize};
Point(2) = {-radius, 0, 0, cellSize};
Point(3) = {0, radius, 0, cellSize};
Point(4) = {radius, 0, 0, cellSize};
Point(5) = {0, -radius, 0, cellSize};
Circle(6) = {2, 1, 3};
Circle(7) = {3, 1, 4};
Circle(8) = {4, 1, 5};
Circle(9) = {5, 1, 2};
Line Loop(10) = {6, 7, 8, 9};
Plane Surface(11) = {10};
''' % locals()) # doctest: +GMSH
T = CellVariable(name = "HeatingUp",mesh = mesh,value = T0)
viewer = None
if __name__ == '__main__':
try:
viewer = Viewer(vars=T, datamin=T0, datamax=Tu)
viewer.plotMesh()
input("Irregular circular mesh. Press <return> to proceed") # doctest: +GMSH
except:
print("Unable to create a viewer for an irregular mesh (try Matplotlib2DViewer or MayaviViewer)")
# =============================================================================
eq = TransientTerm(coeff=rho*cv)==DiffusionTerm(coeff=lam)
T.faceValue.constrain(alp/lam*(Tu-T.faceValue),where=mesh.exteriorFaces) # Boundary Condition for Solver
timeStepDuration = 0.1
steps = 10
for step in range(steps):
eq.solve(var=T, dt=timeStepDuration) # doctest: +GMSH
if viewer is not None:
viewer.plot() # doctest: +GMSH
``
You've written that T.faceValue depends on T.faceValue, which depends on T.faceValue, which depends on T.faceValue, ... FiPy has dutifully provided you with the infinite loop that you requested.
Just write T.faceValue.constrain(Tu * (alp/lam) / (1 + alp/lam), where=mesh.exteriorFaces).
In the more likely event that you wanted to relate the gradient to the value at the boundary, please see the discussion on Robin conditions.

Weird behaviour than animating lines with rgl and rglwidget

I am trying to follow help and Internet examples to create a very simple animation of a 3d-line in R. This is just a test and my final goal is to use this functionality to visually verify results of some geometrical transformations on 3d-movement data that I am analysing. So basically I need nothing more than a ‘3d-player’ interface that allows for usual interaction (rotation, zoom, play, stop, slide).
I figured out that rgl package does the job and I am able to use it for the sphere/points animation. But now I need to use it on lines and I get very strange results. In the example below there are 4 points and two lines (cyan and red) that connect the same points but the red line is for some reason in the ‘wrong’ place. The animation doesn’t make sense neither. Now, I am thinking may be it is impossible to do >> to animate more than one vertex with more than one attribute? But I don’t see this in documentation and obviously it is possible because line is animated! I spent quite a long time trying to figure out what is going on and will appreciate any help/advise/directions. many thanks
Ps: Tthe code below is a chunk in the markdown file and I am using Rstudio.
require(rgl)
require(rglwidget)
p11=c(0,0,0)
p21=c(50,50,0)
p12=c(50,0,0)
p22=c(10,50,50)
saveopts <- options(rgl.useNULL = TRUE)
did=list()
did[[1]]=plot3d(rbind(p11,p21,p12,p22), type="s", alpha = 1, lwd = 5, col = c('brown','darkgreen','orange','green'))
did[[2]]=spheres3d(c(100,100,100), alpha = 1, lwd = 5, col = "blue",radius=2)
did[[3]]=lines3d(rbind(p11,p21),lwd=8, col='cyan',alpha=.9)
did[[4]]=planes3d(0, 0, 1, 0, alpha=.4, col='green')
did[[5]]=lines3d(rbind(p11,p21),lwd=2, col='red')
aspect3d(1, 1, 1)
did[[6]]=grid3d(c("x-", "z-"),at = NULL,col = "gray",lwd = .5,lty = 1,n = 5)
sceneT = rglwidget(elementId = "plot3dT",width=500, height=300) #%>%
rgl.ids()
rgl.attrib(id=did[[3]],attrib = c(1:length(did[[3]])))
playwidget(sceneT,list(
vertexControl(values = rbind(c(0,0,0,0,0,0),c(50,50,50,50,50,50)),
vertices = 1:6, attributes = "z", objid = did[[4]], param = 1:2,interp =T),
vertexControl(values = r1,
vertices = 1:2, attributes = c('x',"y","z",'x',"y","z"), objid = did[[5]], param = 1:2,interp =T)),
start = 1, stop = 2, step = .1, precision = 3)
options(saveopts)

Resources