Category: Others

Free and Easy Horizontal Stacked Bar Graphs with Google Colab / Jupyter (as well as Python and Pandas)

Recently, my wife needed to create some stacked bar graphs for her publications. She wasn’t able to find a tool on the internet which allowed her to do this in an easy and shareable way. So I used this opportunity to look into Jupyter Notebooks. These notebooks allow you to document and run code and thus computations on a remote server from your browser and display the results directly in your browser as well

Google offers their version of Jupyter as a free service called Colab. Already having a Google account it was an easy choice to start there. But there are other similar services available on the internet and the code should run there as well (with minimal changes).

The file is quite self explanatory and can be saved within your own Google drive for editing. You can find it here.

The Notebook

Horizontal Stacked Bar Graph

This notebook will create a horizontal stacked bar graph within your browser based on the data you enter below. Just edit the data in 1) and execute the “gray blocks” in 1), 2) and 3) by either pressing “Shift + Enter” or the “Play” button in each blocks top left corner. To see the “Play” button you need to move your mouse over the block.

You can change the design of the graph in 2). This includes the unit which should be displayed on the bar. You will moste likely need to change the position of the legend as it depends on the data and size of the graph. To do this, change the x value of FigLegPosOffset slightly.

The code within a block is written in Python. Everything after a # is considered a comment. So you can add your own comments to your data or your changes.

1) Preparing the Data
Define your data below and execute the block when done. If everything is correct, your data will be displayed as table below the block.

# importing the functions needed to generate the graph 
import pandas as pd

# Axis captions
FigAxiXCap="Cocktails"
FigAxiYCap="Which Cocktail do you want for the Party?"

# Data (beware: the first entry will be displayed last)

## Data Indexes 
DataIndexes = ['Caipirinha', 'Piña Colada', 'Cuba Libre', 'Mai Tai', 'Ipanema', 'Caribbean Night']
## Data Options
DataYesPlease =  [73.2, 23.8, 24.7, 31.2, 56.6, 68.2]
DataSureWhyNot = [20.3, 51.7, 60.3, 19.2,  4.8, 22.3]
DataJustNo =     [ 6.5, 24.5,   15, 59.6, 38.6,  9.5]

## Name of each column (for the legend)
df = pd.DataFrame(data={'Yes, please!': DataYesPlease, 'Sure, why not?': DataSureWhyNot, 'Just no!': DataJustNo})

#-------------------------------------------------------------------------------
#no need to edit below this line
df.index = DataIndexes

# print table for convinience/debugging (transposed)
df

2) Figure Properties

In the block below you can change the format of the figure. When done (or fine with the defaults) execute it to set all properties.

#################
# Figure Design #
#################
#Figure
## Figure Size
FigSizeX = 20
FigSizeY = 5
## Figure background color 
FigBackColor="white"
## Axis Caption Size
FigAxiXCapFontSize=45
FigAxiYCapFontSize=45
## Axis Labels Font Size
FigLabelFontSize=20

# Blocks
## Colormap of the blocks (all Options: https://matplotlib.org/stable/gallery/color/colormap_reference.html)
FigColMap="Pastel2"
## Width of bars (everything above 1 will overlap)
FigBarsWidth=0.8
## FontSize of bar lables
FigBarsFontSize=20
# Data and Captions (needs to be defined)
## Unit to display within bars
FigBarUnit="%"

# Legend
## Legend Font Size
FigLegFontSize=20
## Legend position [best|upper right|upper left|lower left|lower right|right|center left|center right|lower center|upper center|center]
FigLegPos="upper center"
## Figure OffSet (will move the legend box slightly to match actual figure position)
FigLegPosOffset=(1.11, 1.0)

## 3) Generate and Display the Figure
The block below will generate the figure. You do not need to change anything here. Just be sure to execute it again **after changing anything above**.

# define plot type and layout
ax = df.plot(stacked=True, kind='barh', figsize=(FigSizeX, FigSizeY), colormap=FigColMap, width=FigBarsWidth, fontsize=FigBarsFontSize, xlim=[0,100])

# Add labels to the bars 
# Attribution: Trenton McKinney on StackExchange: https://stackoverflow.com/a/60895640/3764407 CC BY-SA 4.0
for rect in ax.patches:
    # Find where everything is located
    height = rect.get_height()
    width = rect.get_width()
    x = rect.get_x()
    y = rect.get_y()
    
    # The width of the bar is the data value and can be used as the label
    label_text = ""
    if width > 4:
      label_text = f'{width:.1f}' + FigBarUnit  ##### use {width:.2f} or {width:.3f} to increase precision  ####
    
    # ax.text(x, y, text)
    label_x = x + width / 2
    label_y = y + height / 2

    # plot only when height is greater than specified value
    if height > 0:
        ax.text(label_x, label_y, label_text, ha='center', va='center', fontsize=FigBarsFontSize)

# Set legend position and style
ax.legend(bbox_to_anchor=FigLegPosOffset, loc=FigLegPos, borderaxespad=0., fontsize=FigLegFontSize)    
# Set y label
ax.set_ylabel(FigAxiXCap, fontsize=FigAxiXCapFontSize)
# Set x label
ax.set_xlabel(FigAxiYCap, fontsize=FigAxiYCapFontSize)
# Set Background Color
ax.set_facecolor(FigBackColor)

3) Generate and Display the Figure
The block below will generate the figure. You do not need to change anything here. Just be sure to execute it again after changing anything above.

define plot type and layout
ax = df.plot(stacked=True, kind='barh', figsize=(FigSizeX, FigSizeY), colormap=FigColMap, width=FigBarsWidth, fontsize=FigBarsFontSize, xlim=[0,100])

# Add labels to the bars 
# Attribution: Trenton McKinney on StackExchange: https://stackoverflow.com/a/60895640/3764407 CC BY-SA 4.0
for rect in ax.patches:
    # Find where everything is located
    height = rect.get_height()
    width = rect.get_width()
    x = rect.get_x()
    y = rect.get_y()
    
    # The width of the bar is the data value and can be used as the label
    label_text = ""
    if width > 4:
      label_text = f'{width:.1f}' + FigBarUnit  ##### use {width:.2f} or {width:.3f} to increase precision  ####
    
    # ax.text(x, y, text)
    label_x = x + width / 2
    label_y = y + height / 2

    # plot only when height is greater than specified value
    if height > 0:
        ax.text(label_x, label_y, label_text, ha='center', va='center', fontsize=FigBarsFontSize)

# Set legend position and style
ax.legend(bbox_to_anchor=FigLegPosOffset, loc=FigLegPos, borderaxespad=0., fontsize=FigLegFontSize)    
# Set y label
ax.set_ylabel(FigAxiXCap, fontsize=FigAxiXCapFontSize)
# Set x label
ax.set_xlabel(FigAxiYCap, fontsize=FigAxiYCapFontSize)
# Set Background Color
ax.set_facecolor(FigBackColor)

4) Download the Figure (from Google Colab)
To export the generated figure use the following block. You can change the file name and type as well as its resolution (dots per inch/DPI).

# Define the file name
FigureFileName="figure"
# Define the type (jpg, png, pdf, svg)
FigureFileType="png"
# Define DPI (setting this too high might result in long wait times and finally an error)
FigureDPI=30

# do not edit below
FigFile=FigureFileName + "." + FigureFileType
ax.figure.savefig(FigFile,dpi=FigureDPI,bbox_inches = 'tight')
from google.colab import files
files.download("/content/" + FigFile )

 

Which programming language is the best one?

street sign "dead end"

Is it really possible to answer this question?

Yes, the correct answer is: all of them. Or let’s ask another question first: for which problem?

There is not “the one and only” best programming language, there are tons. This question is simply not a good one. It’s good for endless discussion, but it’s neither complete, nor does it give you details about the problem to solve. An answer will not solve the unknown problem of the author. Every coding language has it advantages when it comes to solving a specific problem. But which one? There are advantages for JavaScript, Python, PHP, Java, Swift, Dart and others. But what if the author wants to write some firmware for a micro controller? Ok, you see the point.

But why do people ask those questions?

I see a lot of such questions posted on all social platforms. And as those questions are so incomplete, there are no correct answers. The results are endless discussions about the advantages of each coding language. And this is what most of the authors want: an open question which leads to endless attention. In detail: likes and retweets to pretend the algorithms to be an interesting account. Honestly, no one reads through thousands of responses. And if yes, you only see the advantages that each comfortable developer or user sees in his area of expertise. This might lead to some short attention, but it will never create some high quality and valuable content fo the users. And that’s a pity.

And what about: iOS or Android? Windows or macOS? Python or JavaScript? Same thing! The answers are just a time wasting mess.

Photo by Donald Giannatti on Unsplash.

 

CUDART Error in Singularity Container Workaround

Singularity is a Linux container system similar (and compatible to) Docker. It’s advantage over Docker is that is was designed to allow users without superuser privileges to run containers within their environment. I recently encountered the following error when running a Nvidia CUDA application within a Singularity container using “singularity run -nv <container>:

CUDART: cudaGetDeviceCount(&deviceCount); = 999 (unknown error)

Workaround: After running /usr/local/cuda/samples/1_Utilities/deviceQuery/deviceQuery outside of the container, the CUDA application within the container ran without any problem.

Fix/Solution: TODO

TRÅDRFRI: two controllers for a group of lamps

TRÅDRFRI

By default, a group of lamps (or even a single lamp) can only be controlled by a single TRÅDRFRI controller. But in different situations, it would be better to have multiple controllers to control the lamps, e.g. on a long floor.

This scenario is not described by IKEA and therefore theoretically not supported. But wait… the following steps allow to create a “copy” of controller that can control the same group of lamps (or single lamp).

The starting point is: having a group of lamps or a single lamp paired with a TRÅDRFRI controller.

  1. Reset a new TRÅDRFRI controller (press the ? symbol on the back 4 times)
  2. Place the new and the existing controller next to each other
  3. Hold both of the ? symbol
    1. red light appears … hold the buttons
    2. red light switches off … paring finished
  4. Now it’s possible to use both controllers for the same group of lamps or single lamp

Source: https://www.107er.net/

Wakeboarden und Wasserski für jedermann

Wo kann man Wakeboarden?

Cableparks
Wakeboarding und Wasserski lässt sich in an zahlreichen Wasserskianlage (den sogenannten Cableparks) fahren. Allein in Deutschland gibt es über 80 Anlagen für dieses Vergnügen.

Boote
Neben Cableparks ist es auch möglich, sich hinter einem Boot über das Wasser ziehen zu lassen. An vielen Seen gibt es hierfür Anbieter, die diesen Spaß stundenweise anbieten und man weder einen Sportbootführerschein, noch ein Boot besitzen muss. Für Anfänger ist der Cablepark jedoch vorzuziehen.

Ab welchem Alter kann man Wakeboarden?

Ein festes Alter zum Wakeboarden festzulegen ist schwierig. Hier kommt es immer darauf an: was traut man seinem Kind zu bzw. was traut sich das Kind selbst zu. Wichtig ist auf jeden Fall, dass das Kind selbstständig schwimmen kann und damit im Cablepark eigenständig an Land kommt. Ein Schnupperkurs sollte hier Klarheit verschaffen. Dabei wird meist mit Wasserski begonnen, um ein Gefühl für den Zug und den Verlauf der Bahn zu bekommen. Mit ausreichender Sicherheit kann dann auf ein Wakeboard gewechselt werden. Was auch immer hilft: Vorkenntnisse im Skifahren oder Snowboarden (allerdings ist das kein Muss). Und wie bei jeder Sportart gilt: je früher, desto besser. Und am wichtigsten: es muss Spaß machen!

Welche Ausrüstung ist erforderlich?

Für den Anfang ist keine eigene Ausrüstung erforderlich. An den Cableparks kann man fast immer das notwendige Equipment ausleihen. Angefangen beim Neoprener (besonders empfehlenswert an kühlen Tagen), über Schwimmweste, bis hin zum wichtigsten: Wasserski oder Wakeboard ist hier alles verfügbar.

Pro-Tipp: wer handwerklich begabt ist, der kann sich seine Ausrüstung natürlich auch selbst bauen 😉

Photo by KaLisa Veer on Unsplash

Hello World in 74 natural languages

Hello World is the example of coding which is used to show that a code snippet is running in a specific programming language. But how do you say “Hello World” in different natural languages?

LanguageTranslation
Afrikaans: Hello Wêreld!
Albanian: Përshendetje Botë!
Amharic: ሰላም ልዑል!
Arabic: مرحبا بالعالم!
Armenia: Բարեւ աշխարհ!
Basque: Kaixo Mundua!
Belarussian: Прывітанне Сусвет!
Bengali: ওহে বিশ্ব!
Bulgarian: Здравей свят!
Catalan: Hola món!
Chichewa: Moni Dziko Lapansi!
Chinese: 你好世界!
Croatian: Pozdrav svijete!
Czech: Ahoj světe!
Danish: Hej Verden!
Dutch: Hallo Wereld!
English: Hello World!
Estonian: Tere maailm!
Finnish: Hei maailma!
French: Bonjour monde!
Frisian: Hallo wrâld!
Georgian: გამარჯობა მსოფლიო!
German: Hallo Welt!
Greek: Γειά σου Κόσμε!
Hausa: Sannu Duniya!
Hebrew: שלום עולם!
Hindi: नमस्ते दुनिया!
Hungarian: Helló Világ!
Icelandic: Halló heimur!
Igbo: Ndewo Ụwa!
Indonesian: Halo Dunia!
Italian: Ciao mondo!
Japanese: こんにちは世界!
Kazakh: Сәлем Әлем!
Khmer: សួស្តី​ពិភពលោក!
Kyrgyz: Салам дүйнө!
Lao: ສະ​ບາຍ​ດີ​ຊາວ​ໂລກ!
Latvian: Sveika pasaule!
Lithuanian: Labas pasauli!
Luxemburgish: Moien Welt!
Macedonian: Здраво свету!
Malay: Hai dunia!
Malayalam: ഹലോ വേൾഡ്!
Mongolian: Сайн уу дэлхий!
Myanmar: မင်္ဂလာပါကမ္ဘာလောက!
Nepali: नमस्कार संसार!
Norwegian: Hei Verden!
Pashto: سلام نړی!
Persian: سلام دنیا!
Polish: Witaj świecie!
Portuguese: Olá Mundo!
Punjabi: ਸਤਿ ਸ੍ਰੀ ਅਕਾਲ ਦੁਨਿਆ!
Romanian: Salut Lume!
Russian: Привет мир!
Scots Gaelic: Hàlo a Shaoghail!
Serbian: Здраво Свете!
Sesotho: Lefatše Lumela!
Sinhala: හෙලෝ වර්ල්ඩ්!
Slovenian: Pozdravljen svet!
Spanish: ¡Hola Mundo!
Sundanese: Halo Dunya!
Swahili: Salamu Dunia!
Swedish: Hej världen!
Tajik: Салом Ҷаҳон!
Thai: สวัสดีชาวโลก!
Turkish: Selam Dünya!
Ukrainian: Привіт Світ!
Uzbek: Salom Dunyo!
Vietnamese: Chào thế giới!
Welsh: Helo Byd!
Xhosa: Molo Lizwe!
Yiddish: העלא וועלט!
Yoruba: Mo ki O Ile Aiye!
Zulu: Sawubona Mhlaba!

Source StackExchange. Photo by Kobu Agency on Unsplash.

Kitesurfen in Sachsen

Während Windsurfer in Sachsen ohne große Einschränkungen die Seen befahren können, sieht es für Kitesurfer ganz anders aus: im Raum Leipzig beispielsweise ist der Hainer See einer der wenigen – oder sogar der einzige – See, an dem Kitesurfen erlaubt ist.

Das könnte sich jedoch bald ändern:
https://weact.campact.de/petitions/kitesurfen-in-sachsen

Danke fürs unterzeichnen! Je mehr Menschen die Petition unterstützen, desto größer ist die Wahrscheinlichkeit, dass sie Erfolg hat.

Photo by Dekeister Leopold on Unsplash

Bouldern in der Boulderlounge Chemnitz

Waren heute in der Boulderlounge in Chemnitz. Ab 21:00 wurden Routen umgeschraubt, wodurch leider kein entspanntes Bouldern mehr möglich war. In Chemnitz ist insbesondere die Trainingsecke sehr interessant. Als Inspiration für die eigene Bouldertrainingsecke bzw. Klettertrainingsecke haben wir mal zwei Fotos gemacht:

Die Boulderlounge wird im nächsten Jahr in ein neues Gebäude mit “mehr Platz und Licht” umziehen. Wir sind gespannt!

Nachtrag: Die Boulderlounge ist nun schon seit einiger Zeit in der neuen Location angekommen und hat dabei nicht zu viel versprochen. Das lichtdurchflutete neue “alte” Industriegebäude bietet mit 850 qm Kletterfläche zahlreiche Bereiche die das Bouldern sehr Abwechslungsreich machen. Auch die Trainingsecke hat wieder ein neues Gimmick dazubekommen: eine “LED-Wand”, die sich über eine App steuern lässt. Kleine LEDs neben den Griffen zeigen Dir, welcher Griff als nächstes zu greifen ist – leider auf Grund mangelnder Kondition selbst noch nicht ausprobiert.

Also nichts wie hin in die neue Boulderlounge! Als Vorbereitung auf den nächsten Boulder-Ausflug hier noch eine Packliste mit den wichtigsten Utensilien für Indoor in der Halle (oder auch Outdoor am Fels). Solltest Du doch etwas vergessen haben, dann können bestimmte Dinge, auch in der Boulderlounge vor Ort ausgeliehen werden.