I have a chart with two Y-Axis. One Axis is only a linear line, where you can enter the start and ending point via parameter. The other one is a bar chart, which reads data from a database. My problem is, that the scale of the Y-Axis is not matching. For example the bar axis gets to 1500 at the highest point. The line axis can get higher. Therefore I want to edit the scale of the bar axis in the beforeGeneration script of the chart, so that it´s matching the line axis scale.
Its pretty simple to do that, but when I want to read the min and max of the scale, I only get a null as result.
yAxis = chart.getOrthogonalAxes( xAxis, true)[0];
yscale = yAxis.getScale();
min = yscale.getMin();
max = yscale.getMax();
Then I tried to do it with the parameter, but that is also not working. For some reason Iam not able to read the parameter in the chart script.
yAxis = chart.getOrthogonalAxes( xAxis, true)[0];
yscale = yAxis.getScale();
yscale.setMax( NumberDataElementImpl.create(params["EndwertPara"].value));
yscale.setMin( NumberDataElementImpl.create(0));
yAxis.setScale(yscale);
Error: ReferenceError: "params" is not defined. at line 37 of chart script:
Any idead how to match the scale of the two Y-Axis?
Related
Have been trying to set xticks on an hv.Bars element chart
gamma_plt=hv.Bars(s2,'StrikePrice','TotalGamma', label='Total Gamma').opts(height=400,width=1000,tools=['hover'],xrotation=90)
gamma_plt
Gives a plot that has too many ticks to clearly read them
gamma_plt=hv.Bars(s2,'StrikePrice','TotalGamma', label='Total Gamma').opts(height=400,width=1000,tools=['hover'],xrotation=90,xticks=10)
gamma_plt
gives no output at all. Have tried many other ways to specify ticks by list etc. and always the same result, no plot when I add xticks.
If I set yticks it works as expected on the y axis, but there is no output with any value of xticks
If I change the Bars Element to the Curve Element it works, but Bars does not display
This simple example from the documentation,
ys = np.random.randn(101).cumsum(axis=0)
curve = hv.Bars(ys, ('x', 'x-label'), ('y', 'y-label'))
(curve.relabel('No axis').opts(xaxis=None, yaxis=None) +
curve.relabel('Bare axis').opts(xaxis='bare') +
curve.relabel('Moved axis').opts(xaxis='top', yaxis='right'))
(curve.relabel('N ticks (xticks=10)').opts(xticks=10) +
curve.relabel('Listed ticks (xticks=[0, 1, 2])').opts(xticks=[0, 50, 100]) +
curve.relabel("Tick labels (xticks=[(0, 'zero'), ...").opts(xticks=[(0, 'zero'), (50, 'fifty'), (100, 'one hundred')]))
Also does not work when you choose Bars and does work when you use Curve
Any input would be appreciated.
I want to plot contour plots using plot_ly in R.
My plots should all have the same z-axis scale.
Using plot_ly(type = "contour"), the ranges of x-axis and y-axis can be changed,
but I could not find a way to change the z-axis.
I've already tried autocontour = F + contours() but it did not work. Is there another way to change the z-axis range?
I am trying to create a boxplot in R, however, I find that the figure has wrong tick values for the y-axis.
The .rdata is available at https://www.dropbox.com/s/vbgf3mhgd2mjx8o/Mydata2.rdata?dl=0
load("Mydata2.rdata",.GlobalEnv)
boxplot(Value~Type+Level, data=Mydata2)
As the figure shows, the y-axis is marked "0, 50, 100", however, my data range from -36.9 to 133.7. I wonder how to fix this?
Here, I used min, mean, and max for the tick marks. You can set them to any value manually or even have more than 3 ticks. yaxt="n" prevents the default tick marks and then by using axis and setting the side to 2 (axis(2,...) I add my desired tick marks. Read about ?axis in R.
boxplot(Value~Type+Level, yaxt="n", data=Mydata2)
axis(2,
at=round(c(min(Mydata2$Value), mean(Mydata2$Value), max(Mydata2$Value)),1),
labels = T)
Follow up question: How the default tick marks are computed?
"When at = NULL, pretty tick mark locations are computed internally (the same way axTicks(side) would)."
So, your code is working. Default tick marks are picked by boxplot so it is prettier (well pretty is subjective).
Two methods:
Set each tickmark individually via axis's at argument (at is a numeric vector defining each tickmark):
boxplot(Value~Type+Level, yaxt="n", data=Mydata2)
tickmarks = c(min(Mydata2$Value), max(Mydata2$Value))
axis(2, at = round(tickmarks,1))
Define the range for your tickmarks via boxplot's ylim argument. So, to set the range for your tickmarks between -40 and 140:
boxplot(Value~Type+Level, data=Mydata2, ylim=c(-40,140))
Method #2 works sometimes but not always. Method #1 is more reliable and customizable and should therefore be used more often.
For the plot on RIGHT, becuase the bar and line have same scale and limit, so I used the method as follow
(method 1):
mybar<-barplot(x,names.arg=1:10) // create variable for plot
lines(mybar,y,type="o",pch=19,lwd=2) // add line which points to x-axis
but for LEFT plot, the barplot data has limit (0,20000) and the lineplot data has limit (0,100000), I tried the above method, but it didn't work (it didn't give error, but the line didn't show). Then I tried the mothod as below
(method 2):
barplot(rbind(colum1,column2), names.arg=nameColumn,
las=2, ylim=c(0,20000))
par(new = T)
plot(column3, axes = F, type="b",pch=20)
axis(4, at= ,labels= )
How do I centered the point to each bar for the LEFT plot? would method 1 solve the problem?
Thanks.
I found the solution myself.
Firstly in the left plot, the values of line plot were incorrect. Method 1 would work (align the point to the bar), just need to scale the values of line plot.
plot(column3/5, axes = F, type="b",pch=20)
The reason of " it didn't give error, but the line didn't show" was because the left plot limit was set to (0, 20000), the values of line plot exceeded 20000 before scaling.
The plot after correction:
====== Update ======
This website gives me a lot helps for this solution: www.cs.odu.edu
Here is my data file in (update 2021: link is dead... http://s.yunio.com/87HT7f), please download it and save it as mydata.
y<-scan("mydata")
hist(y,breaks=c(0,60,70,80,90,100),freq=TRUE)
axis(2,at=seq(0,20,length.out=5),labels=c(0,5,10,15,20))
There are two problems:
1.Warning message:
In plot.histogram(r, freq = freq1, col = col, border = border, angle = angle, :
the AREAS in the plot are wrong -- rather use freq=FALSE
I just want freq not probability, times counted on the y axis, how to make the warning message vanish?
2.When run
axis(2,at=seq(0,20,length.out=5),labels=c(0,5,10,15,20))
There no 20 on y axis.
For the first problem, it is a warning, not the error. This warning says that visually areas of each bar do not correspond to their actual frequency - you can see it from the first bar that has the largest area but frequency is only 5.
For the second problem, you have to set ylim=c(0,20) inside hist() to see also number 20 because y axis is shorter than 20. Function axis() plots just labels, it doesn't change length of axis (originally there is no space for number 20).
hist(y,breaks=c(0,60,70,80,90,100),freq=TRUE,ylim=c(0,20))
axis(2,at=seq(0,20,length.out=5),labels=c(0,5,10,15,20))
Check the manual for hist:
freq:
Defaults to 'TRUE' _if and only if_ 'breaks' are equidistant
(and 'probability' is not specified).