I have two arrays of strings: these two arrays contain the labels that are to be inserted on the x and y axis (these labels will be those of a heatmap).
nutsNames corresponds to the x axis (left to right) and the yearsNames corresponds to the y axis (top to bottom).
As the data may vary, I would like to create a way that fits the data.
So the problem is the positioning of the elements on the axes and the svg size.
What I would like to get is something like this:
The image shows two examples of different data.
(I don't want to show axes, I put them only to understand what is their direction).
Here is the plunker.
I thought about finding the longest string in nutsNames and multiplying it by a constant (which I don't know how to define) to create the minimum necessary width of the svg.
A similar thing I did it for years.
Obviously the code doesn't work.
What you can do is input some dummy numbers for the width,height and margins and let it draw the elements first. Now since all your axis labels are in a g , you can get the width of gs for x and y labels.
The group<g> tag wraps the contents inside it so getting its width/height will automatically give you the width/height of the largest text inside it.
Now you have the width and height of those gs, all that's left is to change the dimensions of the svg accordingly.
Try adding or removing labels in your data. Here's your Plunker
Related
We have a chart with two y-axis scales (left and right) but the grid lines are not aligned each other. The input is dynamic and sometimes, the axis point is not a multiple of 2/5/10. For example, in one of the case, we noticed, our right y-axis is measured in 10 points but left y-axis is in 7 points (which is not a specific requirement though). Is there a way to make these grid lines aligned to both right and left y-axis scales?
I know there's a name for this, but I can't seem to think of it (or even provide a better title description.)
Image an empty horizontal rectangle - left edge has a value of 0, right edge has a value of 5. Now above it, there's a graph with an x-axis range of 0-5. When the plotting of the graph begins, the x-axis value is used as input to the horizontal rectangle in order to show, using a specific color, the area of the value.
Example: when input is given to the rectangle, the graph's x-axis value is 2.5. The rectangle now has half of it's area covered in red starting from the left edge. The value now is 3. Same idea, the area now stretches to "3".
It's a dynamic horizontal graph of sorts. Anywho, how do I go about creating this for iOS? Is there a class that's already built? Or do I just use rectangle drawing methods in a UIView subclass?
Thanks
update: here's an image of what I'm after: Bar
I know that I can vary marker position using mlabv() and creating a position variable for individual points on my twoway scatter plot.
Is there a way to do a similar thing for mlabgap()?
I am trying to have certain points' labels a little further away from the rest to avoid overprinting.
http://www.stata.com/help.cgi?marker_label_options implies that the gap is constant in each graph call.
That does not rule out e.g.
scatter y x if group == 1. mlabel(foo) mlabgap(1) ///
|| scatter y x if group == 2, mlabel(foo) mlabgap(2)
Another trick is adding spaces as prefix or suffix to the marker label variable in various observations as needed.
I have a binary which has some text on different parts of the image like at the bottom, top, center, right middle center, etc.
Original Image
The areas I would like to focus on are the manually drawn regions shown in red.
I calculated the horizontal and vertical summations of the image and plotted them:
plot(sum(edgedImage1,1))
plot(sum(edgedImage1,2))
Can somebody give me explanation of what these plots are telling me about the original image with regards to the structure of which I explained above?
Moreover, how could these plots help me extracting those regions I just manually drew in red?
There's nothing sophisticated about the sum operation. Simply put, sum(edgedImage1,1) computes the sum of all rows for each column in the image and that is what you are plotting. Effectively, you are computing the sum of all non-zero values (i.e. white pixels) over all rows for each column. The horizontal axis in the plot denotes what row's sum you are observing. Similarly, sum(edgedImage,2) computes the sum of all columns for each row of the image and that is what you are plotting.
Because your text is displayed in a horizontal fashion, sum(edgeImage,1) won't be particularly useful. What is very useful is the sum(edgedImage,2) operation. For lines in your image that are blank, the horizontal sum of columns for each row of your image should be a very small value whereas for lines in your image that contain text or strokes, the sum should be quite large. A good example of what I'm talking about is seen towards the bottom of your image. If you consult between rows 600 and 700, you see a huge spike in your plot as there is a lot of text that is surrounded between those rows.
Using this result, a crude way to determine what areas in your image that contain text or strokes in your case would be to find all rows that surpass some threshold. Combined with finding modes or peaks from the sum operation that was just performed, you can very easily localize and separate out each region of text.
You may want to smooth the curve provided by sum(edgedImage,2) if you decide to determine how many blobs of text there are. Once you smooth out this signal, you will clearly see that there are 5 modes corresponding to 5 lines of text.
The second plot that shows the sum of each row. This can tell you in which rows you have a lot of information and in which you have none.
You can use this plot to find the rectangles by looking for a sharp incline in the value for a start of a rectangle and sharp decline in the value for the end of the rectangle. Before you do it i would low pass filter the data and then look at the derivative of this and look for a big derivative.
You can do the same the first plot but it is more sensitive.
The minimums in your last plot are the gaps between lines of text ...
You just take the graph and align its y axis to y axis of image and then Threshold areas with too small amount of pixels per column. These areas (Red) are the gaps between lines of Text or whatever you got on the image:
Now you should de-skew the image if needed. If the skew is too big you need to apply the de-skew even before the y axis summation.
De-skew operation characters in binary image (matlab)
After this you make the x axis summation plot for each non red region separately and in the same manner detect gaps between characters/words to get the area of each character for OCR. This time you align to x axis
These plots can be also used to OCR if taken on character region instead see
OCR and character similarity
If you do a statistical analysis of the gap/non gap sizes then the most recurrent one is usually the Font spacing/size for regular text.
I want to align image X against image Y. Each image contains circles and Hough transform is used to detect them.
Lets assume Hough transform detects different number of circles in image X and image Y.
I want to find transformation of image X (rotation, translation) such that most circles in image X match some circle in image Y. Can you tell me how would you proceed?
An approach:
Get some properties from the circles of images X and Y, such as radius or others (color?).
Find putative matches between the circles of X with those of Y. It is to say, two circles with a similar radius are a putative match. You may obtain several matches, correct and incorrect ones.
Use a RANSAC-like algorithm to find the transformation:
Select two random pairs of matching circles and compute the translation and rotation that these define.
Check how many putative matches are ok if you assume the previous transformation (translation + rotation) was ok.
Repeat.
Keep the transformation that maximizes the number of matching circles.