I am trying to set the bg-color of a string-field so that if the value of the field starts with an 'R' it sets the background colour to red. When the value is 'R080' the following expression works correctly:
=IF([Scored_Individual]="R080"; "#FF0000"; "#FFFFFF")
I would like to change this to be true when [Scored_Individual] starts with 'R'. I have found that there is a subString function but the documentation for this is still to be written: http://wiki.pentaho.com/display/Reporting/SubStringExpression
I have tried the following:
=IF([Scored_Individual].substring(0)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].substring(1)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].substring(0,1)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].substring(0)='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].substring(1)='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].substring(0,1)='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].subString(0)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].subString(1)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].subString(0,1)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].subString(0)='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].subString(1)='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].subString(0,1)='R'; "#FF0000"; "#FFFFFF")
and all of the above again, but with == instead of =
I have also tried using left:
=IF([Scored_Individual].left(0)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].left(1)="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].left(0)='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].left(1)='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].left(0)=="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].left(1)=="R"; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].left(0)=='R'; "#FF0000"; "#FFFFFF")
=IF([Scored_Individual].left(1)=='R'; "#FF0000"; "#FFFFFF")
None of these worked. How do you use substring? Is there a better way to do this?
PRD uses OpenFormula, which is based on spreadsheet formulas as used by LibreOffice and Openoffice. Therefore you use the same logic as you would in OpenOffice (or Excel, for that matter).
=IF(LEFT([Scored_individual]; 1) = "R"; "#FF0000"; "#FFFFFF")
Related
I'm creating tissue masks for a bunch of pathology images and in one of the steps for preparing them ı had to change the black pixels to white.
my code works for one image but when I want to apply it to image file in a directory I received this error :
I don't understand the error and don't know to solve it.
File "/Users/sepideh/Library/CloudStorage/GoogleDrive-.../My Drive/Remove_empty_pixels/Remove_empty_pixels.py", line 108, in <module>
height, width, _ = img.shape
File "/Users/sepideh/opt/anaconda3/envs/myenv/lib/python3.9/site-packages/PIL/Image.py", line 529, in __getattr__
raise AttributeError(name)
AttributeError: shape
and this is my code :
height, width, _ = img.shape
white_px = np.asarray([255, 255, 255])
black_px = np.asarray([0 , 0 , 0 ])
img2 = np.array(img, copy=True)
for i in range(height):
for j in range(width):
px = img[i][j]
if all(px == black_px):
img2[i][j] = white_px
I want to understand the reason for this error and a solution for it.
I would like to append a color bar to my image to indicate what value corresponds to which color.
Something similar to the calibration bar in ImageJ.
Thank you for your help
What you are looking for is the "Intensity bar".
Example script right from the F1 help documenation:
image img := RealImage("Test",4,512,512)
img = itheta
img.ShowImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
number kSCALEBAR = 31
number kINTENSITYBAR = 33
component scalebar = NewComponent( kSCALEBAR, 450, 100, 480, 300 )
disp.ComponentAddChildAtEnd( scalebar )
component intbar = NewComponent( kINTENSITYBAR, 50, 400, 450, 490 )
disp.ComponentAddChildAtEnd( intbar )
I want to add labels to my ggplot2 bars and change the color of the label. Somehow I can't.
My dataset is (simplified) approximatly in this format:
data$value <- runif(27, min=10, max=60)
data$A <- factor((rep(1:3, each=9)))
data$B <- factor((rep(1:9, each=3)))
data$variable <- factor(rep(rep(1:3),9))
The plot would be like:
three <- c(pink="#BD1550",dark="#490A3D",blue1="#0b6fa1",white="#FFFFFF", "#FFFFFF")
m<- data %>% group_by(A, variable) %>% summarise(mean=mean(value), sd=sd(value)) %>%
ggplot(aes(x=A,fill=variable)) +
geom_col(aes(y=mean),position="stack")+
geom_text(aes(label=round(mean,digits=2),y=mean, colour="white")
,size=3, show.legend = F, position = position_stack(vjust = 0.5))+
scale_fill_manual(values=three) + theme(legend.position="right")
Now, for the colour in geom_text I have tried:
color="white"
spelling color or colour
colour="#FFFFFF"
colour=c("#FFFFFF")
colour = 4
color = white
one <- c("#FFFFFF") and then colour = one
Different solutions give different colors for each label, pink, orange, green, a blue from my string 'three', but never give me the color white. I have also tried to make it different colors than white, but somehow I have no control over what color it gives me back.
I get no error messages.
I am starting to run out of ideas. Anyone any solutions?
The problem is that your are mapping "white" on the color aesthetic inside aes(). This way ggplot thinks you want to map a variable on the color aesthetic, i.e. "white" is not interpreted as the name of a color. Instead ggplot simply picks the color from its default palette, which is "red". Simply pass the color as an argument to geom_text outside of aes(). Or use scale_color_manual to set the color palette. (; Try this:
library(ggplot2)
library(dplyr)
set.seed(42)
data <- data.frame(
value = runif(27, min=10, max=60),
A = factor((rep(1:3, each=9))),
B = factor((rep(1:9, each=3))),
variable = factor(rep(rep(1:3),9))
)
three <- c(pink="#BD1550",dark="#490A3D",blue1="#0b6fa1", white="#FFFFFF", "#FFFFFF")
m <- data %>%
group_by(A, variable) %>%
summarise(mean=mean(value), sd=sd(value)) %>%
ggplot(aes(x=A, fill=variable)) +
geom_col(aes(y = mean),position="stack")+
geom_text(aes(label = round(mean, digits=2), y=mean), colour="white"
,size=3, show.legend = F, position = position_stack(vjust = 0.5))+
scale_fill_manual(values=three) + theme(legend.position="right")
m
Created on 2020-04-14 by the reprex package (v0.3.0)
The following output code outputs an array from the manipulate statement. I would like to output the fitting and plot as two separate output cells that update dynamically. I think it should be pretty simple, but I am having trouble with it. I've tried using the CellPrint[] function, but did not get it to work.
Thanks,
Tal
temperatures(*mK*)= {300, 200, 150, 100, 75, 50, 25, 11, 10};
F[t_, \[Nu]_] := t^\[Nu];
rd (*uOhms*)= {27173.91304, 31250., 42372.88136, 200601.80542,
1.05263*10^6, 1.33333*10^7, 1.33333*10^8, 2.*10^8, 2.1*10^8};
logRd = Log10[rd];
f[\[Nu]0_] := Module[{\[Nu]},
\[Nu] = \[Nu]0;
data = Transpose[{F[temperatures, \[Nu]]*10^3, logRd}];
fitToHexatic = LinearModelFit[data[[4 ;; 6]], x, x];
plota =
Plot[fitToHexatic["BestFit"], {x, 0, data[[-1]][[1]]},
Axes -> False];
plotb = ListPlot[data, Axes -> False];
{fitToHexatic, Show[{plota, plotb}, Axes -> True]}
]
Manipulate[
f[nu],
{nu, -0.2, -1}
]
Screenshot of the output:
You don't need to use a Manipulate. You can get more control with lower level functions. E.g.
Slider[Dynamic[nu, (f[#]; nu = #) &], {-0.2, -1}]
Dynamic[Normal[fitToHexatic]]
Dynamic[Show[{plota, plotb}, Axes -> True]]
See also Prototypical Manipulate in lower level functions.
I would like to have a module like this
TestModule[n_] := Module[{{dataList = {{0, 0}, {1, 2}}}},
For[i = 1, i <= n, i++,
Pause[0.5];
Print[ ListLinePlot[dataList++]];
];
];
where a the values of a list get updated from iteration to iteration and instead of having the module producing me n plots, I rather would like to have only one plot, which is updated n times after each iteration.
I looked already at Dynamics[] and Monitor[], but could not yet find a solution with them. Any help is appreciated. :)
here is a straightforward application of Monitor:
TestModule[n_] := Module[{
dataList = {{0, 0}, {1, 2}},
plot = "starting..."
},
Monitor[
Do[
Pause[0.5];
plot = ListLinePlot[dataList++, PlotRange -> {0, n + 2}],
{i, 1, n}
],
plot
];
plot
];
Do you know mathematica.stackexchange.com? You'll get much more answers for Mathematica specific questions there...