Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
QKDNetJournal/math2matlab.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
182 lines (161 sloc)
5.02 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
x = 0:pi/10:2*pi; | |
y1 = sin(x); | |
y2 = sin(x-0.25); | |
y3 = sin(x-0.5); | |
y4 = cos(x-0.5); | |
figure | |
plot(x,y1,'g',x,y2,'b--o',x,y3,'r:*',y1,y1) | |
title('2-D Line Plot') | |
xlabel('x') | |
ylabel('cos(5x)') | |
legend('sin(x/2)','2016') | |
saveas(gcf,'Barchart1.png') | |
""" | |
input_file = "charts.txt" | |
datax=[] | |
datay=[] | |
data_order = [] | |
legend = [] | |
styles = ["r-.*","b--o", "m:+","r-s","b-d", "m-p"] | |
try: | |
with open(input_file, "r") as f: | |
skip = False | |
print("close all") | |
for line in f.readlines(): | |
#print("line", line) | |
if line[0] == "\"" or not "{" in line: | |
continue | |
if "Export" not in line: | |
if "(*" in line: | |
line = line.split("(*")[0] | |
if "*)" in line: | |
line = line.split("*)")[1] | |
if ";" in line: | |
line = line.split(";")[0] | |
line = line.replace("*^", "e") | |
if "=" in line and not "data" in line and not "legend" in line and not "Print" in line: | |
s = line[line.index("=")+1:].replace("}"," ").replace("{"," ").replace(";\n","").split(",") | |
#print(s) | |
data_order.append(line[:line.index("=")].strip()) | |
x = [] | |
y =[] | |
for i in range(0,len(s), 2): | |
x.append(s[i].replace("=","")) | |
y.append(s[i+1].replace("=","")) | |
datax.append(x) | |
datay.append(y) | |
print("{}X = {};".format(data_order[-1].strip(),[float(f) for f in x])) | |
print("{}Y = {};".format(data_order[-1].strip(),[float(f) for f in y])) | |
#make xy list | |
# print(line) | |
# print(s) | |
# print(data_order[-1]) | |
# print("x",x) | |
# print("y", y) | |
pass | |
if "data" in line and not "Plot" in line: | |
#make_list of data | |
s = line[line.index("=")+1:].replace("}"," ").replace("{"," ").replace(";\n","").split(",") | |
#print(line) | |
#print(s) | |
if len(s) <= 3 and "Global" in line and line.count("Global") ==1: | |
new_order = [None for i in s] | |
for i in s: | |
if "Global" in i: | |
new_order[0] = i | |
if "NIA" in i: | |
new_order[2] = i | |
if "IA" in i: | |
new_order[1] = i | |
#print(data_order) | |
data_order = new_order | |
else: | |
#print("LINE", line) | |
data_order = [leg for leg in s] | |
# print("LINE", line) | |
# print(data_order) | |
#print(data_order) | |
if "legend" in line and "Plot" not in line: | |
s = line[line.index("=")+1:].replace("}"," ").replace("{"," ").replace(";\n","").split(",") | |
if len(s) <= 3 and "Global" in line and line.count("Global") ==1: | |
new_order = [None for i in s] | |
for i in s: | |
if "Global" in i: | |
new_order[0] = i | |
if "NIA" in i: | |
new_order[2] = i | |
if "IA" in i: | |
new_order[1] = i | |
legend = new_order | |
else: | |
legend = [leg for leg in s] | |
# print("LINE", line) | |
# print(legend) | |
#print(data_order) | |
# print(legend) | |
if "Plot" in line: | |
#make_graph, add labels, save | |
xlabel = None | |
save_file = None | |
if "Export" in line: | |
s = line.split(",")[0].split("/")[-1] | |
save_file = "~/research/QKDNetJournal/graphics2/{}".format(s).replace("\"","") | |
else: | |
s = line.split(",")[0].split("/")[-1] | |
save_file = "~/research/QKDNetJournal/scratch.pdf" | |
xlabel = line.split("AxesLabel")[1].split("\"")[1] | |
if xlabel == "L": | |
xlabel = "Fiber Length (km)" | |
if xlabel == "Q" or xlabel == "B": | |
xlabel = "BSM Success prob." | |
if xlabel == "E" or xlabel == "D": | |
xlabel = "Decoherence prob." | |
if xlabel == "S": | |
xlabel = "Size" | |
datax_o=datax | |
datay_o=datay | |
legends_o = legend | |
args = [] | |
args1 = [] | |
data_order = [d.replace("\"", "") for d in data_order] | |
for i in range(len(data_order)): | |
try: | |
args1+=["{}X".format(data_order[i].strip()),"{}Y".format(data_order[i].strip()), "'{}'".format(styles[i] if i < len(styles) - 1 else None)] | |
except: | |
print(i) | |
print(len(data_order)) | |
exit() | |
args = [a for a in args1 if not "None" in a] | |
print("figure('units','normalized','outerposition',[0 0 1 1])") | |
print("plot({},'LineWidth',5, 'MarkerSize',25)".format(",".join(args))) | |
print("title('')" ) | |
print("set(findall(gcf,'-property','FontSize'),'FontSize',40)") | |
print("legend([{}],'FontSize',35, 'Location', 'north', 'EdgeColor', 'none')".format(",".join(legends_o))) | |
print("ylabel('Key Rate')") | |
print("xlabel('{}')".format(xlabel)) | |
if "ize" in xlabel: | |
print("xticks([5,7,9,11,13,15])") | |
if "BSM" in xlabel: | |
print("xticks([.65,.75,.85,.95,1])") | |
if "ength" in xlabel: | |
print("xticks([1,3,5,7,9,11,13,15,17,20])") | |
#print("figh = gcf;\npos = get(figh,'position');\nset(figh,'position',[pos(1:2)/4 pos(3:4)*2])") | |
#print("saveas(gcf,'{}')".format(save_file)) | |
print("fig = gcf;\nfig.PaperSize;\nfig.PaperPositionMode = 'auto';\nfig_pos = fig.PaperPosition;\nfig.PaperSize = [11 fig_pos(4)-1];") | |
#print("print('{}.pdf','-dpdf', '-bestfit')".format(save_file[:-4])) | |
print("print('{}.pdf','-dpdf', '-fillpage')".format(save_file[:-4])) | |
print("\n\n") | |
datax=[] | |
datay=[] | |
data_order = [] | |
legend = [] | |
datax_o=[] | |
datay_o=[] | |
legend_o = [] | |
except Exception as e: | |
print(e) | |
print("here") | |
print(line) | |
exit(0) | |
print("close all") |