Morris chart set y axis value - morris.js

I am trying to display a chart for app ranking using morris.js. The ranks will be between 1 to 50. So there will not be 0 rank. I want the max y axis value to be 1, not 0. Please review the images. How can i configure this? Please help.
(source: perk.com)

Use ymin (or ymax, if you invert the scale).
http://www.oesmith.co.uk/morris.js/lines.html

Related

Plotting an exponential function given one parameter

I'm fairly new to python so bare with me. I have plotted a histogram using some generated data. This data has many many points. I have defined it with the variable vals. I have then plotted a histogram with these values, though I have limited it so that only values between 104 and 155 are taken into account. This has been done as follows:
bin_heights, bin_edges = np.histogram(vals, range=[104, 155], bins=30)
bin_centres = (bin_edges[:-1] + bin_edges[1:])/2.
plt.errorbar(bin_centres, bin_heights, np.sqrt(bin_heights), fmt=',', capsize=2)
plt.xlabel("$m_{\gamma\gamma} (GeV)$")
plt.ylabel("Number of entries")
plt.show()
Giving the above plot:
My next step is to take into account values from vals which are less than 120. I have done this as follows:
background_data=[j for j in vals if j <= 120] #to avoid taking the signal bump, upper limit of 120 MeV set
I need to plot a curve on the same plot as the histogram, which follows the form B(x) = Ae^(-x/λ)
I then estimated a value of λ using the maximum likelihood estimator formula:
background_data=[j for j in vals if j <= 120] #to avoid taking the signal bump, upper limit of 120 MeV set
#print(background_data)
N_background=len(background_data)
print(N_background)
sigma_background_data=sum(background_data)
print(sigma_background_data)
lamb = (sigma_background_data)/(N_background) #maximum likelihood estimator for lambda
print('lambda estimate is', lamb)
where lamb = λ. I got a value of roughly lamb = 27.75, which I know is correct. I now need to get an estimate for A.
I have been advised to do this as follows:
Given a value of λ, find A by scaling the PDF to the data such that the area beneath
the scaled PDF has equal area to the data
I'm not quite sure what this means, or how I'd go about trying to do this. PDF means probability density function. I assume an integration will have to take place, so to get the area under the data (vals), I have done this:
data_area= integrate.cumtrapz(background_data, x=None, dx=1.0)
print(data_area)
plt.plot(background_data, data_area)
However, this gives me an error
ValueError: x and y must have same first dimension, but have shapes (981555,) and (981554,)
I'm not sure how to fix it. The end result should be something like:
See the cumtrapz docs:
Returns: ... If initial is None, the shape is such that the axis of integration has one less value than y. If initial is given, the shape is equal to that of y.
So you are either to pass an initial value like
data_area = integrate.cumtrapz(background_data, x=None, dx=1.0, initial = 0.0)
or discard the first value of the background_data:
plt.plot(background_data[1:], data_area)

Chart axis increments vb

I am trying to place some reasonable axis increments on my vb .net graph. I have used:
Chart1.Series(0).Points.DataBindXY(Wavelength, Normalised)
Chart1.ChartAreas(0).AxisX.RoundAxisValues()
Chart1.ChartAreas(0).AxisX.Minimum = 0
Chart1.ChartAreas(0).AxisX.Maximum = 2048
Chart1.ChartAreas(0).AxisX.Interval = 100
Which plots the graph corresponding to indicies 0 to 2048, in intervals of 100. However as the x axis array starts at 341.1049 and has non integral spacings, the x axis has nasty data labels with many decimal points.
Is there a way of displaying from say 300 to say 10000 with increments of 100?
Here's my chart, see the increments have many decimals and aren't nicely spaced
It is because the AxisX.Maximum and .Interval uses interval spacings of the X axis series and not actual values. Though I can't seem to find any reference of any alternatives.
Now, I understood what you were asking. Intervall is not what you are looking for. You need AxisX.MajorUnit. Intervalls says after how many points should a label be rendered. For ex. if you set it to 1 you will have a label on your axis for every point in the series.
With MajorUnit and MinorUnit you control what you mean as Intervall.
Here you have sth that could help you, you can use the LabelStyleFormatlike this to format your axis labels:
With Chart1.ChartAreas(0).AxisX
.Minimum = 300
.Maximum = 10000
.MajorUnit= 100
'//Here you can format the axis labels
.LabelStyle.Format = "0.###"
.Title = "TestTitle"
.TitleFont = New Font(New FontFamily("Arial"), 9, FontStyle.Bold)
End With
This is for the X axis, to change the Y axis just use Chart1.ChartAreas(0).AsisY.

How can I find (generate) data points form a shape in 2D in MATLAB ? For example, the letter A , B ,and C. Thanks

How can I find or generate data points form a shape in 2D in MATLAB ? For example, the letters A, B, and C.
You can use fill()
An example for an octogon, provided by
See https://www.mathworks.com/help/matlab/ref/fill.html
% Generate the points required for the fill.
t = (1/16:1/8:1)'*2*pi; % using 1/8 steps we get an 8 sided object.
x = cos(t);
y = sin(t);
% fill the data
fill(x,y,'r')
axis square % prevent skewing the result.
An example of generating the x y coordinates of a rectangle with an offset of (5,5):
x=[5 5 25 25 5]
y=[5 15 15 5 5]
You have 5 points because you need to include the final point to complete the path ( I believe ) Follow the blue path when collecting the x coordinates and the y coordinates. You can see we start at 5,5 then move to 5,15 --- so the first part of the path is
x=[5 5 ...
y=[5 15 ...
If you want to generate the coordinates automatically, you could use a program like InkScape (vector program) to help you convert a character to paths, but here is a simple example drawn with the pen tool:
The points are given by
m 0,1052.3622 5,-10 5,0 5,10 z
which 1052.3622 is VERY large, but is ultimately because I placed my shape at the bottom of the page. if we set this to be 0,0 it would go to the top of the page.

Find or calculate intersection points of a straight line with a diagonal scatter plot using VBA

I am trying to understand how I can go about finding or calculating the intersection points of a straight line and a diagonal scatter plot. Just to give a better idea, on an X,Y plot, if I have a straight horizontal line at y= # (any number), that crosses an array of scatters points (which form a diagonal line), how can I calculate points of intersection the two lines?
The problem that I am having is that the scattered array has multiple points around my horizontal line, what I would like to do is find the point that hits the horizontal line first, and the point that hits the horizontal line the last.
please refer to the image for a better understanding. The two points that are annotated are the ones that I am trying to extract with VBA. Is this possible? The image shows two sets of scattered arrays, I am only interested in figuring out the method for 1 of the arrays. If I can extract this for 1 scattered array, I can replicate the method for the next one.
http://imgur.com/9YTNeco
It's hard to give you any specifics without knowing the structure of your Data. But this is the approach I'd use.
I'll assume your data looks like this (for both of the plots)
A B
x1 y1
x2 y2
x3 y3
Loop through the axis like so:
'the y values need to be as high as the black axis you've got there
'I'll assume that's zero
i = 0
k = .Cells(1,1)
'we begin at the first x-value in your column
for i = 0 to Worksheets("Sheet name").UsedRange.Rows.Count
'now we are looking for the lowest value of x, k will be this value
if .Cells(i,1) < k Then
if .cells(i,2) = 0 Then '0 = y-value of the "black" axis
k = .Cells(i,1)
End If
End If
'every time we find a lower value than our existing k
'we will assign it to k
Next
The lowest value will be your "low limit"-point.
You can use that same kind of algorithm for the highest value of the same scatter plot (just change the "<" to ">" or the lowest and highest value for the one, just change the Column ID.
HTH

How to draw an alternating line with pyplot?

I have a series of x coordinates (e.g.: 1,2,3,4) and y coordinates (e.g.: 10,20,30,40). I would like pyplot to draw a line between two consecutive points, while skipping every other line (e.g.: draw a line between (1,10) and (2,20), and a line between (3,30) and (4,40).)
How can this be done?
Do you mean something like this?
x = [1,2,3,4,5,6]
y = [10,20,30,40,50,60]
for n in np.arange(0,len(x),2):
plt.plot(x[n:n+2],y[n:n+2])
(Copied from #Floris' comment above)
The quick and dirty trick would be to insert NaN values in the arrays at every third position (both X and Y).