Font size doubles unexpectedly in rmarkdown - r-markdown

The figure font size doubled unexpectedly between knits. Restarting R did not fix the issue. I ended up decreasing font size by 50% to fix the problem. Has this happened to anyone else? My theme is shown below.
style <- theme(plot.title = element_text(face = "bold", size = 30),
plot.subtitle = element_text(size = 30),
axis.title = element_text(size = 25, face="italic"),
axis.text = element_text(size = 25),
legend.text = element_text(size = 25),
legend.title = element_text(face = "bold", size = 25),
legend.position = "bottom",
panel.background = element_rect(fill = NA),
panel.grid.major = element_line(colour = "grey88"),
axis.ticks = element_line(color=NA),
axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)),
axis.title.x = element_text(margin = margin(t = 20, r = 0, b = 0, l = 0)))

If it changes between knits, maybe you were zoomed in on your web browser and didn't know it. it also might depend on your knit R chunks. if you can't replicate the issue, it might just be a random issue.

Related

Same formula different behaviour

I have a Google Sheet with a formula that calulates a price based on different data provided by a Google Form. If I use arrayformula (my formula) in some cases I have a wrong calculation, while if I type the formula directly in the cell I receive the right output.
I've solved the issue by removing the arrayformula, but I wonder if there might be a different solution
This sometimes fails:
=arrayformula(SE(X2:X = "SI";SE(AB2:AB = "SI"; SE(E(Z2:Z = "SI"; Y2:Y = "NO");15;40); 50); SE(AC2:AC = "SI"; SE(AE2:AE ="SI"; SE(E(Z2:Z = "SI"; Y2:Y ="NO");10;25); 35); 50)))
This is working:
=SE(NON(VAL.VUOTO(X9));SE(X9:X = "SI";SE(AB9 = "SI"; SE(E(Z9 = "SI"; Y9:Y = "NO");15;40); 50); SE(AC9 = "SI"; SE(AE9 ="SI"; SE(E(Z9 = "SI"; Y9 = "NO");10;25); 35); 50));)
Text is in Italian, the keywords are:
SE = IF
E = AND
NON = NOT
VAL.VUOTO = ISBLANK
your arrayformula should be:
=ARRAYFORMULA(
IF(X2:X = "SI";
IF(AB2:AB = "SI";
IF((Z2:Z = "SI") * (Y2:Y = "NO"); 15; 40); 50);
IF(AC2:AC = "SI";
IF(AE2:AE = "SI";
IF((Z2:Z = "SI") * (Y2:Y = "NO"); 10; 25); 35); 50)))

matplotlib legend at the bottom of the figure with twinx

I am trying to draw a legend under two plots (created using twinx). I want the legend to draw at the bottom center aligned with 4 columns. So far no success. How can I make the legend with respect to the entire plot, not just with a single axis object. Any help ?
import matplotlib.pyplot as plt;
import numpy as np;
from matplotlib import rc;
filename = 'ml.pdf';
fig, ax1 = plt.subplots(frameon=False);
rc('mathtext', default='regular');
rc('lines',lw=2.6);
rc('lines',mew=2.4);
rc('text', usetex=True);
x = np.array([5,10,20,50]);
dp_g = np.array([23.43, 29.93, 36.50, 46.07]);
mr_g = np.array([25.33, 31.83, 38.39, 47.75]);
md_g = np.array([24.94, 31.33, 37.80, 47.10]);
sb_g = np.array([27.01, 34.86, 43.18, 54.35]);
lns1 = ax1.plot(x,dp_g,'bs:', label="MD\n($\lambda$=.8)");
lns2 = ax1.plot(x,mr_g,'bs--',label="MR\n($\lambda$=.1)");
lns3 = ax1.plot(x,md_g,'bs-.',label='MD');
lns4 = ax1.plot(x,sb_g,'bs-',label="SB\n($\gamma$=.1)");
ax1.set_ylabel('CG ($\times$ 100)',color='b',size=14);
ax1.set_ylim([20,57]);
ax1.set_xlim([4,51]);
ax1.set_xticks(x);
ax1.tick_params(axis='y', which=u'both', length=0, labelsize=14, colors='b');
ax1.tick_params(axis='x', which=u'both', length=0, labelsize=14);
ax2 = ax1.twinx();
dp_d = np.array([18.84, 19.55, 20.09, 20.08]);
mr_d = np.array([19.42, 19.73, 20.06, 20.04]);
md_d = np.array([19.02, 19.75, 20.28, 20.29]);
sb_d = np.array([20.81, 19.77, 19.20, 19.03]);
lns6 = ax2.plot(x,dp_d,'rv:',label="MD\n($\lambda$=.8)");
lns7 = ax2.plot(x,mr_d,'rv--',label="MR\n($\lambda$=.1)");
lns8 = ax2.plot(x,md_d,'rv-.',label='MD');
lns9 = ax2.plot(x,sb_d,'rv-',label="SB\n($\gamma$=.1)");
lns = lns1 + lns2 + lns3 + lns4 + lns6 + lns7 + lns8 + lns9;
labs = [l.get_label() for l in lns];
ax2.set_ylabel('LD ($\times$ 100)',color='r',size=14);
ax2.set_ylim([15,23]);
ax2.set_xlim([4,51]);
ax2.set_xticks(x);
ax2.tick_params(axis='y', which=u'both', length=0, labelsize=14, colors='r');
ax2.tick_params(axis='x', which=u'both', length=0, labelsize=14);
ax1.set_xlabel('\# of items',size=14);
borderaxespad=2.5, ncol = 1, fontsize='11.5');
lgd = ax1.legend(lns, labs, bbox_to_anchor=(1.01,1.0), loc='lower center', borderaxespad=2.5, ncol = 4, fontsize='14');
fig.savefig(filename,format='pdf',transparent=True, bbox_extra_artists=(lgd,), bbox_inches='tight');
Apart from the broken line borderaxespad=2.5, ncol = 1, fontsize='11.5');, I believe what you want to do is to just remove the bbox_to_anchor=(1.01, 1.0) from the legend-definition. Doing so will put the legend at the bottom center of the plot (however the legend is very wide so it will span the entire width of the plot).

Update textbox with text from browsed file. python

I am currently using Python 2.7 and Tkinter. I have a button that browses my directory and takes the file's directory location and saves it to filename. I would like this to change the value of inputBox to the value of filename automatically when the file is chosen.
import os
from Tkinter import *
import tkFileDialog
root = Tk()
root.title("Doc Word Frequency")
root.geometry("600x300")
def close_window ():
root.destroy()
def browse_directory():
filename = tkFileDialog.askopenfilename()
print(filename)
#Change value of inputBox
inputBox = Entry(root, width = 50)
inputBox.grid(row = 0, column = 0, padx = 20, pady = 20)
inputBox.insert(END, '"Upload Document File"')
inputBox.config(state = DISABLED)
Button(root, width = 9, text = 'Browse', command = browse_directory).grid(row = 0, column = 1, sticky = W, padx = 4)
Button(root, width = 9, text = 'Upload').grid(row = 0, column = 2, sticky = W, padx = 4)
Button(root, width = 9, text = 'Quit', command = close_window).grid(row = 0, column = 3, sticky = W, padx = 4)
mainloop( )
PS. I am quite new to Python and any constructive criticism would be appreciated.
You can insert text into an entry widget with the insert method.
def browse_directory():
filename = tkFileDialog.askopenfilename()
print(filename)
inputBox.configure(state=NORMAL)
inputBox.delete(0, "end")
inputBox.insert(0, filename)
inputBox.configure(state=DISABLED)

changing sprite frame depending on random value

I have a list of buttons(currently images) and i want to change the image color depending on the value that is taken from the list
buttons = {"btn1","btn2","btn3","btn4"}
local buttonSheetData = {
width = 150,
height = 150,
numFrames = 2,
sheetContentWidth = 300,
sheetcontentheight = 150,
}
local buttonSheet = graphics.newImageSheet("image/buttonSS.png", buttonSheetData)
local sequenceData = {
{name = "black", start = 1, count = 1},
{name = "red", start = 2, count = 1}
}
local btn1 = display.newSprite(buttonSheet, sequenceData)
btn1.x = 100
btn1.y = 90
local btn2 = display.newSprite(buttonSheet, sequenceData)
btn2.x = 200
btn2.y = 230
local btn3 = display.newSprite(buttonSheet, sequenceData)
btn3.x = 300
btn3.y = 90
local btn4 = display.newSprite(buttonSheet, sequenceData)
btn4.x = 400
btn4.y = 230
x = buttons[math.random(#buttons)]
x:setFrame(2)
The circles are currently black. every time i run the code i want it to take a random value from the list and change the color to red. so there is a different red circle when i run the code
I keep getting the error:
"Attemp to call method 'setSequence' (a nill value)"
You're code is treating strings and variable names as if they are interchangeable. The first line:
buttons = {"btn1","btn2","btn3","btn4"}
creates a table of strings, so the line:
x = buttons[math.random(#buttons)]
will set x to be a random entry of buttons which are strings so the next line (x:setFrame(2)) is calling a method that doesn't exist on a string.
Instead, create a table of your buttons:
buttons = {btn1,btn2,btn3,btn4} -- creates a table of buttons
x = buttons[math.random(#buttons)] -- x is a random entry of buttons (a button)

Difference between two volume files

I want to render volume(X.volume()) and cube(X.cube()) on one scene. For testing I use your volume files from lessons.
Case 1:
var r = new X.renderer3D();
r.init();
var volume = new X.volume();
volume.center = [0, 0, 0];
volume.file = 'http://x.babymri.org/?avf.nrrd';
var cube = new X.cube();
cube.lengthX = cube.lengthY = cube.lengthZ = 20;
cube.center = [0, 0, 0];
cube.color = [1, 1, 1];
r.add(volume);
r.add(cube);
r.render();
This case works fine, as expected:case 1.
Case 2:
var r = new X.renderer3D();
r.init();
var volume = new X.volume();
volume.center = [0, 0, 0];
volume.file = 'http://x.babymri.org/?vol.nrrd';
var cube = new X.cube();
cube.lengthX = cube.lengthY = cube.lengthZ = 20;
cube.center = [0, 0, 0];
cube.color = [1, 1, 1];
r.add(volume);
r.add(cube);
r.render();
This case works unexpected, cube center is shifted: case 2.
What is the difference of this two files?
As far as I remember, 'center' is not actually used for the volume.
The volume is displayed in the 'ANATOMICAL COORDINATE SYSTEM'.
http://www.slicer.org/slicerWiki/index.php/Coordinate_systems#Anatomical_coordinate_system
Practically, it means that avf.nrrd was actually centered on 0-0-0 when the data was acquired, whereas vol.nrrd was not.
Calling 'center' on the volume has NO effect.
As for now, the best workaround it to display the cube in the volume's center directly.