Google Charts - Change the Order of Lines drawn - google-visualization

I have the following array that I wish to turn into a Google line chart:
array = [
['Period 12', '165', '183'],
['Period 11', '145', '133'],
['Period 10', '125', '143'],
...
]
The 1st column represents the label on the x-axis, the 2nd is the value for the current period and the 3rd is the value for the last period.
I am using formatters for the number values so that they show a prefix ($ or £).
I push each row into Google's TableData, I set the current trend line to be bright blue and the previous one a faded blue. This is the result:
As you can see, the previous trend line is drawn 'over' the current one. I was wondering is it possible to 'flip' the order in which they're drawn?
I've tried pushing the values of the 3rd column first and then the 2nd column AND flipping the colors of the trend lines. But in that case the popups on the points show the wrong periods (light blue becomes current period and light blue - previous period) like so:
I've check and double checked this approach, but it doesn't seem to work.
Any help is appreciated!
PS: Sorry for the links, reputation doesn't allow posting images directly.

Don't know if you solved the problem, but I had a similar problem with the ordering. In my case having a pointSize added to the options was the problem, eventho I changed the order of the columns. Removing the pointSize solved the problem.

Related

Determine when a cell is blank

At work, I needed that if the value of a cell is equal to the cell next to it, then the background color changes to red, but it is doing it for blank cells, so it may be confusing for others.
Is there a way to avoid blank cells?
I have this formula:
=IF($D2=$C2,TRUE)
then background color changes to red (not sure if the correct formula, but it worked at the beginning, I am doing this in the Conditional Format Rules in Google Sheets).
I used this:
=IF($D1=$C1,IF(ISBLANK($D1),FALSE,TRUE))
I set the range to be C1:D1000. Your formula was putting the formatted color on the row above the data being checked. This formula checks if they are equal. Then if so it checks if one is blank. You don't have to check if they are both blank, the formula already knows that they are equal. So then if they are equal, return false, otherwise return true.
Clear formatting from C2 to wherever in ColumnD suits and with that selected then Format - Conditional formatting..., Custom formula is and:
=($C2=$D2)*($C2<>"")
Then select formatting of choice and Done.

RRD Graph - Change line colour by value

I have a RRD database with data:
"DS:pkts_transmitted:GAUGE:120:0:U",
"DS:pkts_received:GAUGE:120:0:U",
"DS:pkts_lost:GAUGE:120:0:U",
"DS:rtt_min:GAUGE:120:0:U",
"DS:rtt_avg:GAUGE:120:0:U",
"DS:rtt_max:GAUGE:120:0:U",
And I want that the Avg line change colour if I lose any package.
For example, if I lose 5 packets make the line blue, if I lose 10 make it red.
I see people doing it but I read the documentation and I can't find how to do this.
The way to do this is to actually have multiple lines defined (one of each colour) and hide the ones you don't want to see at any time, using calculations.
For example, say we have an RRD with two DSs:
DS:x:GAUGE:60:0:U
DS:y:GAUGE:60:0:1
Now, we want to show the line for x in red if y is 0, and blue if it is 1. To do this, we create two calculated values, x1 and x2.
CDEF:x1=y,0,EQ,x,UNKN,IF
CDEF:x2=y,1,EQ,x,UNKN,IF
Thus, x1 is active if y=0 and x2 if y=1. Yes, this could be simplified, but I'm showing it like this for the example.
Now, we can make lines using these:
LINE:x1#ff0000:MyLine
LINE:x2#0000ff
Note that the second line doesn't need a legend. Now, the line will appear to change colour depending on the value of the y metric, since at any time the other line will be UNKN and therefore not displayed.
You can extend this, of course, to have multiple colours and more complex thresholds.

Pyplot rotated labels offset by one

Just getting into matplot lib and running into odd problem - I'm trying to plot 10 items, and use their names on the x-axis. I followed this suggestion and it worked great, except that my label names are long and they were all scrunched up. So I found that you can rotate labels, and got the following:
plt.plot([x for x in range(len(df.columns))], df[df.columns[0]], 'ro',)
plt.xticks(range(10), df.columns, rotation=45)
The labels all seem to be off by a tick ("Arthrobacter" should be aligned with 0). So I thought my indexing was wrong, and tried a bunch of other crap to fix it, but it turns out it's just odd (at least to me) behavior of the rotation. If I do rotation='vertical', I get what I want:
I see now that the center of the labels are clearly aligned with the ticks, but I expected that they'd terminate on the ticks. Like this (done in photoshop):
Is there a way to get this done automatically?
The labels are not "off", labels are actually placed via their "center". In your second image, the corresponding tick is above the center of the label, not above its endpoint. You can change that by adding ha='right' which modifies the horizontal alignement of the label.
plt.plot([x for x in range(len(df.columns))], df[df.columns[0]], 'ro',)
plt.xticks(range(10), df.columns, rotation=45, ha='right')
See the comparison below :
1)
plt.plot(np.arange(4), np.arange(4))
plt.xticks(np.arange(4), ['veryverylongname']*4, rotation=45)
plt.tight_layout()
2)
plt.plot(np.arange(4), np.arange(4))
plt.xticks(np.arange(4), ['veryverylongname']*4, rotation=45, ha='right')
plt.tight_layout()

SimpleCV: Removing lines I previously drew?

I'm trying to do edge detection with SimpleCV on a RasPi by first finding all the lines in an image and then filtering items set based on location, intersect angle and color. I have the filtering figured out, but am having difficulty displaying the image with the filtered lines drawn in.
Currently I am can draw the full line set with
handle_lin = my_lines_full.draw()
handle_img = some_image.show()
and the filtered line set independently with
handle_lin = my_lines_filtered.draw()
handle_img = some_image.show()
but since this method also displays the full line set, no difference is seen when I do them in the same script. Whats the best way to erase the layer that stores the line drawings or selectively remove elements of the drawing?
Sovled(-ish):
Seems as though the some_lines.draw() command toggles line sets so by repeating the .draw() command before updating the lines set I can clear the layer that is displayed on the image.

find the same area between 2 images

I want to merge 2 images. How can i remove the same area between 2 images?
Can you tell me an algorithm to solve this problem. Thanks.
Two image are screenshoot image. They have the same width and image 1 always above image 2.
When two images have the same width and there is no X-offset at the left side this shouldn't be too difficult.
You should create two vectors of integer and store the CRC of each pixel row in the corresponding vector element. After doing this for both pictures you find the CRC of the first line of the lower image in the first vector. This is the offset in the upper picture. Then you check that all following CRCs from both pictures are identical. If not, you have to look up the next occurrence of the initial CRC in the upper image again.
After checking that the CRCs between both pictures are identical when you apply the offset you can use the bitblit function of your graphics format and build the composite picture.
I haven't come across something similar before but I think the following might work:
Convert both to grey-scale.
Enhance the contrast, the grey box might become white for example and the text would become more black. (This is just to increase the confidence in the next step)
Apply some threshold, converting the pictures to black and white.
afterwards, you could find the similar areas (and thus the offset of overlap) with a good degree of confidence. To find the similar parts, you could harper's method (which is good but I don't know how reliable it would be without the said filtering), or you could apply some DSP operation(s) like convolution.
Hope that helps.
If your images are same width and image 1 is always on top. I don't see how that hard could it be..
Just store the bytes of the last line of image 1.
from the first line to the last of the image 2, make this test :
If the current line of image 2 is not equal to the last line of image 1 -> continue
else -> break the loop
you have to define a new byte container for your new image :
Just store all the lines of image 1 + all the lines of image 2 that start at (the found line + 1).
What would make you sweat here is finding the libraries to manipulate all these data structures. But after a few linkage and documentation digging, you should be able to easily implement that.