I am trying to parse an excel spreadsheet using "spreadsheet". How could I get the background color of each row?
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet :name => 'Name'
format = Spreadsheet::Format.new :color=> :blue, :pattern_fg_color => :yellow, :pattern => 1
sheet.row(0).set_format(0, format) #for first cell in first row
or
sheet.row(0).default_format = format #for entire first row
you can iterate over each row/cell and apply style exactly where you want
I was looking around for colors that you can use for the background color of a cell. For example:
Spreadsheet::Format.new({ :weight => :bold, :pattern => 1, :pattern_fg_color => :silver })
I couldn't find good info on which colors I could use for :pattern_fg_color. I decided to look for Excel help and found: http://dmcritchie.mvps.org/excel/colors.htm (at "The DOS assignments of the 16 colors").
It looks like the top 16 colors work:
0 Black, 1 Navy, 2 Green, 3 Teal, 4 Maroon, 5 Purple 6 Olive, 7 Silver,
8 Gray, 9 Blue, 10 Lime, 11 Aqua, 12 Red, 13 Fuschia, 14 Yellow, 15 White
I've just been trying to figure out the same, and seems like in the current version (0.6.5.9) of Spreadsheet gem the attribute of cell's background color is not supported in reader (you can only define background color in cells for writing).
Here's how to check all currently available cell attributes:
a = Spreadsheet.open('/folder/spreadsheet.xls')
puts a.worksheets[0].row(<rownumber>).format(<columnnumber>).inspect
After some experimentation however I figured out that not all of them are properly extracted. The good news is that the developers promise to implement better support for cell formats in future versions, so we just need to be patient :)
Related
I'm doing a gif in gnuplot, and I have my data separated in blocks. I need the points to be white except from just the first row of every data block, which would be an orange point.
Currently my code is:
#...
do for [i=0:int(STATS_blocks-1)]{
plot "positions.txt" index i pt 7 ps 0.5 lc 'white' title "t = ".((i+1)*200)." Myr"
}
As you can see, this plots every data point white, including the first row.
Edited to show variable pointsize also
If I understand your data format correctly:
set linetype 11 lc "orange"
set linetype 12 lc "white"
set style data points
do for [i=0:N] {
plot "positions.txt" index i using 1:2:(column(0)>0 ? 0.5 : 2.0):(column(0)>0 ? 12 : 11) pt 7 ps variable lc variable
}
Variable color (if used) is always taken from the very last using column. Other variable properties work back from there.
I'm trying to convert some similar images from gif to png.
You can find two of the pictures here:
https://europa.eu/european-union/about-eu/history/1980-1989_en.
After converting the first gif (for the year 1981), you can see the background colour is the same as before, white, but for the second gif (for the year 1986), the background colour changed to pink. How to fix it?
Below is my code:
file_in = uigetfile('*.*', 'All Files', 'MultiSelect','on');
file_out = cellfun(#(x) cat(2, x(1:(length(x)-3)), 'png'),...
file_in, 'UniformOutput', false);
for i = 1: length(file_in)
[gif,map] = imread (file_in{i});
imwrite (gif, map, file_out{i}, 'Background', [0 0 0]);
end
Matlab have never change the image color after conversion. Thus, if you try to open the 'gif' or 'png' by imshow you will get the same result.
Whatever, if you want to change the background color to white use this code.
Very simple stuff. I want a function, say function f, to be plotted with a particular color. I also want a piece of label saying "function f color" which is also displayed in that color.
I am trying this so far:
set style line 1 lw 3 lc 1
set label "AC" at 0, 70 textcolor 1
but apparently the "lc" and "textcolor" follows different specs, and it complains:
"trolo4.pl", line 8: colorspec option not recognized
any help would be great!
Try this instead:
set label "AC" at 0, 70 textcolor linetype 1
or
set label "AC" at 0, 70 textcolor linespec 1
Read the manual in gnuplot> help label to learn more.
The answer by #holygeek works fine. Coming from python, I find that it is often nice to be a little more explicit.
set style line 1 lw 1 lc rgb "red"
set label "AC" at 0, 70 tc rgb "red"
Note that the set of color names recognized by your gnuplot is system dependent (see show colornames for a complete list). To achieve complete system independence, you can use the #RRGGBB version. e.g. red is '#ff0000, green is #00ff00 and blue is #0000ff. of course, you can make up all sorts of interesting colors (again, see show colornames for a list of pre-defined colors and their equivalent #.....)
for more info, also see help colorspec
I was looking for a way to change the default colors of the different categories in d3.js.
I found where the colors are laid out in the main d3.js. They look like this for one category:
var ml = [2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175].map(yt)
I've tried replacing these values with everything from Hex codes to HSL to RGB and it never yields the expected colors.
Any ideas how I can generate the proper numbers for whatever colors I want?
Thanks.
First, just FYI, to see the RGB (i.e. hex) value that corresponds to these numbers:
(2062260).toString(16); // 16 for hex, aka base 16
> "1f77b4"
Next, given an RGB (again, hex) that you want to convert to number:
parseInt("1f77b4", 16); // 16 for hex
> 2062260
And that would be the number you want to use.
The colors you got from the d3 source are used to construct what you get from d3.scale.category10(). You can get the same thing but with your own colors — and without modifying d3's source code — by constructing a d3.scale.ordinal:
var myCategory3 = d3.scale.ordinal()
.domain(["red", "#1f77b4", "rgb(128, 255, 128)"]);// All kinds of colors are possible
myCategory3("X");// "red"
myCategory3("blabla");// "#1f77b4"
myCategory3("X");// "red"
myCategory3(123456);// "rgb(128, 255, 128)"
Can someone provide some insight on how scales and extents work together in cubism.js
.call(context.horizon()
.extent([-100, 100])
.scale(d3.scale.linear().domain([-10,10]).range([-100,100])
)
);
For example what does the code above do? If the values are generated using a random number generator (numbers between -10 and 10)
I know extent is used to set the maximum and minimum.
I know how to define a scale, example:
var scale = d3.scale.threshold().domain([100]).range([0,100])
console.log(scale(1)) // returns 0
console.log(scale(99.9)) // returns 0
console.log(scale(88.9)) // returns 0
console.log(scale(100)) // returns 100
I read about d3.scales here http://alignedleft.com/tutorials/d3/scales/
My main issue is that I want to define thresholds for my data, very simple
0-98 Red
98-100 Pink
100 Blue
Or maybe just
0-99.99 Red
100 Blue
But I'm not being able to use all what I've read to construct something that works.
I'm guessing that you just want to use a different color to represent anomalies in your data. If that is true, you don't need to create a domain and range.
You can just create a custom color palette like this:
var custom_colors = ['#ef3b2c', '#084594', '#2171b5', '#4292c6', '#6baed6', '#9ecae1', '#c6dbef', '#deebf7', '#f7fbff', '#f7fcf5', '#e5f5e0', '#c7e9c0', '#a1d99b', '#74c476', '#41ab5d', '#238b45', '#006d2c', '#00441b'];
This color palette was constructed using the palette on this page with an extra red color tacked on to the end.
Then just call the custom colors like this:
d3.select("#testdiv")
.selectAll(".horizon")
...
.call(context.horizon()
.colors(custom_colors)
));
Play around with the colors until you find a combination that you like. In this above example, only the outlier will be in red while the rest will follow the blue and green pattern.
Hope this helps!