Skip to content

Instantly share code, notes, and snippets.

View Kappie's full-sized avatar

Geert Kapteijns Kappie

View GitHub Profile
@Kappie
Kappie / add_labels.py
Last active April 3, 2020 16:44
Automatically add figure labels (a), (b), (c), etc. to axes. Labels are located at the top-left of the axis, at the same horizontal position as the y-label.
def add_labels(axes, style=r'(%s)'):
"""
Adds figure labels (a), (b), (c), etc. to axes.
Must be called after plt.tight_layout().
"""
alphabet = 'abcdefghijkl'
labels = [style % letter for letter in alphabet]
# EXTREME hack alert.
@Kappie
Kappie / plot_example.tikz
Created April 18, 2017 12:58
plot_example.tikz
\begin{tikzpicture}
\def \filelocation {'plots/data/order_param_vs_T_q2_N40-1000_trunc_error1e-6.dat'}
\begin{axis}[
name={plot1},
title={blaf},
xlabel={$T$},
ylabel={$M(N, T)$},
legend style = {
legend pos = south west,
@Kappie
Kappie / store_data_of_current_fig_to_file.m
Created April 18, 2017 12:56
store_data_of_current_fig_to_file.m
function store_data_of_current_fig_to_file(filename)
% Get data vectors of current figure
lines = findobj(gca,'Type','line')
file_id = fopen(filename, 'w');
for line = lines'
x = line.XData;
y = line.YData;
fprintf(file_id, '%3f %3f\n', [x; y]);
% Write two blank lines for gnuplot to recognize the next plot as separate.
@Kappie
Kappie / my_export_fig.m
Last active April 18, 2017 12:57
my_export_fig.m
function my_export_fig(filename, scriptname, save_to_thesis_plots_folder)
if nargin == 2
save_to_thesis_plots_folder = false;
end
full_path = fullfile(Constants.PLOTS_DIR, filename);
set(gcf, 'PaperPosition', [0 0 7 5.6]); %Position plot at left hand corner with width 5 and height 5.
set(gcf, 'PaperSize', [7 5.6]); %Set the paper to have width 5 and height 5.
saveas(gcf, full_path, 'pdf') %Save figure
% export_fig(full_path);
function [total_mse] = mse_data_collapse_all_sets(x_values, y_values, L_values)
% We assume (up to corrections to scaling) a universal scaling function
% of the form
% f(t * L^(1/nu)) = L^(-a) * m(t, L)
%
% We assess the fitness of the data collapse by interpolating the data points of one set, and calculating the mean
% squared error (mse) with the points of the other data sets in the overlapping region.
% We repeat this for all sets. (See Bhattacharjee 2001)
% x_values: map from double to array (sorted in ascending order)
@Kappie
Kappie / hline.m
Created September 30, 2016 09:10
The subscript of the label partially disappears into the line. I fixed that in the following way.
% Changed this:
if ~isempty(label)
yy=get(gca,'ylim');
yrange=yy(2)-yy(1);
yunit=(y-yy(1))/yrange;
magic_number = 0.02;
if yunit<0.2
text(x(1)+0.02*(x(2)-x(1)),y+0.02*yrange,label,'color',get(h,'color'))
else
text(x(1)+0.02*(x(2)-x(1)),y-0.02*yrange,label,'color',get(h,'color'))
function correlation_length = correlation_length(temperature, ~, T)
% construct row of spins, and attach two rows together.
transfer_matrix = ncon({T, construct_a(temperature), T}, {[1 -1 -4], [1 -2 2 -5], [2 -3 -6]});
transfer_matrix = ncon({transfer_matrix, transfer_matrix}, {[-1 -2 -3 1 2 3], [1 2 3 -4 -5 -6]});
% reshape into 2chi^2 x 2chi^2 matrix
[transfer_matrix, ~, ~] = lreshape(transfer_matrix, [1 2 3], [4 5 6]);
eigenvalues = eigs(transfer_matrix, 2);
correlation_length = 1 / log(eigenvalues(1) / eigenvalues(2));
require "nokogiri"
BASE_DIR = "../support_vector_machine/data/female_blogs"
TARGET_DIR = "../support_vector_machine/data/female_posts"
Dir["#{BASE_DIR}/*"].each do |path|
blog = Nokogiri::XML(File.open(path))
posts = blog.xpath("//post")
extension = File.extname(path)
<p>Voor middelbare scholieren die willen leren programmeren.</p>
<ul>
<li>Data: <strong>7 t/m 11 juli</strong></li>
<li>Tijd: <strong>13.00 - 16.00 uur</strong></li>
</ul>
<p>Als je meedoet, leer je in vijf dagen de beginselen van programmeren &mdash; de computer laten doen wat je wilt. Je hebt geen programmeerervaring nodig.</p>
<p>Je gaat algoritmes schrijven om priemgetallen te vinden, versleutelde teksten kraken en meer. Na de cursus heb je genoeg geleerd om zelfstandig verder te leren: <a href="http://rubyprog.nl/sinatra/hoofdstuk1">web design</a>, games maken; noem maar op.</p>
<p>We gebruiken Ruby, een uitstekende eerste programmeertaal. <a href="http://rubyprog.nl/ruby/hoofdstuk1">Doe een oefenles</a>.</p>
Voor middelbare scholieren die willen leren programmeren.
- Data: **7 t/m 11 juli**
- Tijd: **13.00 - 16.00 uur**
Als je meedoet, leer je in vijf dagen de beginselen van programmeren &mdash; de computer laten doen wat je wilt. Je hebt geen programmeerervaring nodig.
Je gaat algoritmes schrijven om priemgetallen te vinden, versleutelde teksten kraken en meer. Na de cursus heb je genoeg geleerd om zelfstandig verder te leren: [web design](http://rubyprog.nl/sinatra/hoofdstuk1), games maken; noem maar op.
We gebruiken Ruby, een uitstekende eerste programmeertaal. [Doe een oefenles](http://rubyprog.nl/ruby/hoofdstuk1).