[Why can't I] Save matplotlib plots/graphs/figures

2017-12-07 00:00:00 +0000

More and more of my fellow students and researchers have started to used a tool called Jupyter notebooks to contain perform the data analysis in a contained environment using Python. Including plotting plots using SciPy and matplotlib. Both my colleagues and I really enjoy using these features. However, a lot have initial problems with to things, one is showing the graphs in a Jupyter Notebook and the second is to store the plots.

Here I will illustrated how I do it. First you need to include a few libraries, see code example below and this will allow you to call the needed functions. However, they will not allow you to show, the plots in a Jupyter Notebook. For that you will need to enable inline matplotlib, and that is what the line %matplotlib inline does. So these line should be enough for that part.

import pandas as pd
import numpy as np
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt

So the next thing will be to save the plot and this is where the code gets weird, without looking weird. So in the code below I have omitted loading and analysing data, and basically only focusing on generating the plot figure.

fig = plt.figure()
my_xticks = ['1kB','1MB','10MB','20MB','32MB','64MB','128MB','256MB','512MB']
plt.xticks(data_size, my_xticks)
plt.plot(data_size, latency)
plt.ylabel('Latency in ms')
plt.xlabel('Data size')

The first line generate our figure, this figure, is what we want to save. The next six lines are used to configure the plot. The seventh line fig.savefig('results/graphs/full_vector_gen_32.eps')saves the figure. HOWEVER, based on the documentation for matplotlib that is not enough to save the figure. Because the next line plt.show() is what inline uses to show the figure. BUT! for some reason, this line have to be called for the save function to work. I cannot figure out why and others claim that it works without, but I have not been able to and others I know haven’t either.

But this is how you can use save your figures from a Jupyter notebook. You can store them in different formats, but if you are using latex for your paper or report, why not go with the king .eps.

Introducing: Why can't I

2017-10-03 00:00:00 +0000

Hello, I am going to do something stupid. I am going to make a blog post series and the series is called Why can’t I?. The purpose of this series is to create a set of blog posts which each covers a subject I have discussed with either colleagues or friends, and all have started with the question Why can’t I…

In some cases I will have an answer to why you cannot and in some case I will explain how you can actually do the thing, you think you cannot do.

I filed this under the tags tech, guide, and stuff. The reason is that predominantly it will be tech related and sometimes include a guide. BUT! My friends and I are strange so sometimes it might cover a food related topic or something even stranger.

This is also an attempt to get me blogging more regularly and to increase the content on my blog. I hope you will enjoy it

-Lars Nielsen

Why learning new programming languages are important

2017-10-01 00:00:00 +0000

NOTE: This post will be updated

Almost everyday a new programming language see the dawn of life and quickly flickers into none existence. But once in a while comes a language that will blow away most developers and it will change the way developers like to code or a new language comes with a new a very cool concept. Examples of such languages are LISP, C, Obj-C and C++, Simula. Erlang, and Haskell.

Unfortunately throughout my career as a software developer and student, I have seen a saddening tendency with developers and that is, they do not really want to learn new programming language. This in turn results in developers getting out of sync, with what is actually possible and which languages actually can help you, do your job better.

However, it is true that most companies select one, two, maybe even three languages and stick with them. In Denmark it has a tendency to be C#, Java, JavaScript, and maybe C++, and the only thing really changing are which frameworks are being used.

So why bother learning a new language?

First of learning a new language might force you to learn a new programming paradigm, if you go with Haskell it is the functional paradigm, with Pharo it is the object oriented paradigm, and C would be the imperative programming paradigm. But what good does this do? Firstly, it forces you to think about tasks in a different manner and for instance in the case of functional programming, you are forced to think with a more mathematical mindset, By acquiring a secondary way of thinking, you will adapt to a more multi-phased process when addressing problems and have a better idea about how to solve a given problem.

Secondly, keeping your finger on the pulse of what is happening. By learning new languages or new language concepts, you increase your knowledge and by such your skill set. This allows you to make more informed decision, when choosing language or techniques. This will in tern also make you more desirable for companies to heir, as you have an high level of understanding about what is trending and what could be used to solve a task.

But are the problems?

Yes, there are problems and the problem is learning too many languages. Why is that a problem? Well if you know 10+ languages you will not know them sufficiently in-depth to be called an expert and you will start to confuse languages with each other. In this interview “Bjarne Stroustrup: The 5 Programming Languages You Need to Know” by BigThink, Mr. Stroustrup talks about how many languages you should know and why you should learn new ones.

Another problem, less common in software development circles but on I am guilty of is Language Jumping, if you come from the Linux community you might know the term distro jumper. This is basically the same principal, often switching between programming languages and by such start to confuse them with one another. This gives a high level of confusion, especially if you switch between many languages throughout the day.

So therefore you need to manage how many languages you know and how often you switch between them.

So what programming language do I recommend

First of I am not a UI or web developer anymore and that will be reflected in my list.

So the first language is Go, not because Go is weirdly used, yet, but because for an introduction to and daily work with imperative and semi object oriented programming Go is awesome. It removes the need to know about pointers and how to interact with them, giving a much more approachable way to learn imperative programming. Also if you are truly insane you can 100% mod object orientation in Go. I will not call it true OOP because we only have structs not classes and no inheritance. The language is easy to use and is enforcing a pretty formatting in my opinion.

The second language is… C#, NOT! because it has amazing libraries such as Linq, but because it is a simple and easy to use programming language letting you fully explore the power of both OOP and Imperative programming, you can even mix and match. Furthermore, the language have an enormous use base and amazing documentation, making it easy to join up. Finally with .Net Core Microsoft is allowing both development and deployment of software in C# on Linux and Mac, which you know I am hugh fan of. In the old days I would have said Java due to C# only being windows compliant but not any more.

Thirdly C, though most modern language has abstractions from memory management and pointers, it is still good to have more in-depth understanding of what the is going on. C is harsh in that way, as you have to handle, almost, everything your self and if somethings goes boom it is your fault. Therefore C is on my list. Now also for embedded programming it is also almost a must to know C, but it is not on the list for that reason.

Fourthly, Haskell, now I am not very good a Haskell yet myself as I was taught LISP. But Haskell is one of the cleanest programming languages out there and forces you to learn the functional paradigm. The language is not easy to use nor get use too, if you are more family with imperative and OOP languages. But I think it is worth the time.

Finally, Rust, WHAT THE FUCK IS Rust???? Rust is “newcommer” in terms of programming languages and is used for system programming and Mozilla Servo is made in it. Rust is meant as an alternative to C and it is really easy to understand and learn if you are used to C. Now I am still a newcommer to this language, but I really, really enjoy using it and I see similar run times, compared to C. I can even see Rust as the long awaited replacement for C, if it gets the proper adaptation by the community of embedded and system developers.

This is my current list. I will update this post with more information and more about why I think certain languages is a waste of time and which I think people should consider learning, even if they are not on my list.

-Lars Nielsen

My Experience with the Kinesis Advantage2 LF

2017-06-11 00:00:00 +0000

In Living with RSI as a programmer [1] I discuss how I cope with RSI and how a few possibilities for handling RSI on your own. One of the things I recommend buying and two different keyboards and one option I mention is a ergonomic keyboard, and I even state that I am eyeing the Keyboardio Model 01 [2]. However, this keyboard is brand new and I was unable to find some reviews about it, to get an idea about the quality, and for this reason I decided to buy a different brand. The Chief Technical Officer of Steinwurf Aps [3] have used a Kinesis Advantage for some years now, for similar reasons as me and his experience was that the keyboard was helping him. So based on his recommendations and others recommendation I went a bought a Kinesis Advantage2 Low Force (LF) [4].

So what is my experience with the keyboard so far? So I have had two, I got the first one in April and used it at work and study, whilst I kept using my standard issue Apple numeric keyboard at home. The first few days was strange because I got pain shooting up my arm and it felt like it was from muscles I might not be using when I use an ordinary keyboard. But after this initial use the pain in both my arms and wrist went away and they did not come back. However, the keyboard broke and I could not figure out what was wrong with it and after contacting Kinesis support I got a new keyboard, which is working like a charm.

My initial assessment is that the keyboard works as intended and that my RSI pains has vastly decreases and I only fell a strain every other week instead of every day. So though the keyboard is very expensive it solves my problem so far and I am very happy about it.

I will in the following year continuously document my usage of the keyboard and review its effect on my pain experience



  • [1] Living with RSI as a programmer
  • [2] keybaordio
  • [3] Steinwurf Aps.
  • [4] Kinesis Advantage2 Low Force

Exams Stress and Exams Anxiety

2017-03-09 00:00:00 +0000

All students have tried, whether it was their first exam, one in the middle or the very last one, all students have been nervous before an exam. But some students have worse, some get stressed out by exams, and with this is do not mean the F*ck I didn’t study kind of stress. I mean the students whom have planned their exam period to the very last detail, follows their plan 100% studies all subjects, gets good/great grades and still get the fucked stressed out. However, there is a special group of students whom do not just get stressed the f*ck out. They get anxieties, they can have problems like fainting during the exams or throwing up without any apparent reason. I was one of those students and to some extend still are.

In this post I will explain my experience as a student and how I solved some of the issues. I am, however, not a professional and by such this is not a post detailing a psychological evaluation of my self, nor a recipe for success. The latter simply doesn’t exists and your leg has been pulled, by anyone who told you so.

High School

In high school I was not the best student far from it, I just needed a certain grade average to attend the Computer Science program at Aarhus University and I wasn’t going to do anything extensive to get above that average. By such I actually didn’t care about the exams, I did get nervous close to the exams and by such the exams wouldn’t affect me or so I thought. However, during my senior year I started to experience something, I had never tried experienced before. I started getting sick on the day of written exams and almost on the clock one hour before any written exam, I would have to throw up and again half an hour before. I did the logical thing and talked to my parents, whom assumed, like I, that it was just extensive nerves, which had gotten to me, as it was my senior year and final exams in high school. Then came Aarhus University.

Aarhus University

Oh my f*cking gods what a mess that was for me. Not due to lectures, work load or stuff like that. It was due to exams. At the department of Computer Science at Aarhus University and the remainder of the Science faculty, most students have finals every seven to eight weeks, and instead of working in semesters, the students work in “quarters”, eg. seven weeks. For me this resulted in a lot of stress, because I had to attend exams constantly and though I thought my throwing up days from high school was over, they were not. So instead of having it rough once, I now had it four times a year. However, unlike high school I started seeing an effect at oral exams as well. Which where very problematic, I have once fainted during and exam and once I have forgotten my own name and where I was. So as you can see it got pretty rough. Therefore I stopped at Aarhus University and started looking for other options. I did want a degree in the fields of computer science or related field, so I needed a solution.

Before I started at another educational institution, I worked for six months. During this period a former fellow student made the comment, that I should consider that I did not just have exams stress, but suffered from exams anxiety. But I was macho, heh me macho, and said no that couldn’t be possible. Then I started to attend Business Academy Aarhus and SURPRISE I started throwing up again.

Business Academy Aarhus

At Business Academy Aarhus, I attend the academy profession degree computer science program and during the first semester I had course I was pretty sure I would nail, because I already had passed similar courses at Aarhus University, but even though I had that knowledge I still needed threw up and in some cases even fainted, though luckily at the end of the exam. However, unlike last time where it was a friend whom suggested I might have exams anxiety, this time it was a teacher. The teacher suggest I saw a student psychologist to get it classified if it was just exams stress or anxiety. This time it did not sound so stupid, because it came from an authority and I decided to comply.

The psychologist indeed concluded that I suffered from exams anxiety, though not a server case of it. Otherwise I would have gone completely bongos to exams, I must admit I kind of thought I did. However, she did ask me questions about how I planned my exams and stuff like that, and to my astonishment, she made once comment plan less study more. I took this comment to heart and start to change my study patterns and not planning my exams periods to the very minute. I graduated from Business Academy with the average of average. Meaning I had achieved an average equal to the third highest grade after the danish grading scale. However, I was pleased, because I no longer needed to throw up before written exams and I no longer fainted during oral exams, which is a great plus. I was still nervous but far from the levels I experienced at Aarhus University. This was one of the things which encouraged me to continued my studies and I was accepted to Aalborg University.

Aalborg University

As I am not completely done with my masters yet, 1.5 years to freedom. I cannot fully state it yet. But I will say I still experience nervousness and once I have thrown up, before and exam due to anxiety, but it is still far from what I experienced at Aarhus University and my current grade average is very, very good.

What have I done then to help lessen my anxiety?

Well the first challenge is to accept that you do have anxiety, that was very hard for me and it took me some time to accept it. Secondly stop planing everything, I made a scheduled for reading both during the semester and the exam period, down to the minute and how many pages I needed to read to “succeed”. This was one of the things which gave me stress because it resulted in me felling behind, when I did not reach my planned goal. Leading to me not thinking I would do good, resulting in anxiety. Thirdly take notes rather than study, this one might be more particular too me than others, I stopped reading before lecture, but rather took notes during the lectures and started reading afterwards comparing my notes to what I read, ensuring I had understood things correctly, further ensuring that I believed I could achieve a good result at the exams. Lastly remove your ambitions. In the TV-Show How I meet your mother Nile Patrick Harris starring as Barney Stinson, has the perfect line »Ambition is the enemy of success«. If you start setting high requirements for yourself, you start expecting more of yourself than you are actually capable of. However, if your ambition is to pass an exam, rather than ace it, you will not overload your head with expectations. I do not want you to say f*ck it all. I want you to realise what you are actually capable of.

Those are the things I have done to help lessen my anxiety and hope I will help someone else. Again I am not a professional, so seek one out if you need it.

-Lars Nielsen

subscribe via RSS