Skip to main content

Posts

Showing posts from December, 2016

Create and display images on Jupyter on the fly

Hi, let's rivisit some code. This is for jupyter notebook. Go in the cmd or terminal and start it so: jupyter notebook After the notebook is started write this code: 1. Import the modules from IPython.core.display import display # this is for jupyter from PIL import Image as Img # this to create images from random import shuffle # this to shuffle the cards 2. Create a list with the name of the cards Download the cards: https://apprendimento.github.io/img/cdslittle4.rar unzip them in the dir where the py file is and then in img/cdslittle4/ This is the code that creates a list of all the name images of the cards to be loaded num = [ str ( x ) for x in range ( 1 , 11 )] num [ 0 ] = 'ace' seeds = [ "_of_hearts" , "_of_clubs" , "_of_diamonds" , "_of_spades" ] cards = [ "img/cdslittle4/" + x + s + ".png" for x in num for s in seed...

Different ways to start Python

If you have different versions of python on windows you could start python in the cmd (bash) of windows writing: python or py or py -3 or py -3.4 or py -2.7 When you install python there is an option to check to include python in the path. If you don't check it you can go in the system and add it in the advanced system settings in the system variables.  In the system variables you have to choose the path variable and add the C:\python36 value to the list of value, for example. anyway... there is still this way to start a specific python version from the command line, indicating the full path of python: c:\python34\python.exe

Matplotlib for data in Python 2

Hi. In the last post... we have seen how to make a statistic graph with matplotlib library in python (using Jupyter and a specific version of Python). Now we will use 'scatter' method to plot only the points of the data representing the year and the population of New York City. Here is the code. There are only slight chaanges... the data and the scatter function instead of the plot function % % script c : \python34_32bit\python . exe import matplotlib . pyplot as plt y = [ 1900 , 1910 , 1920 , 1930 , 1940 , 1950 , 1960 , 1970 , 1980 , 1990 , 2000 , 2010 ] p = [ 3437202 , 4766883 , 5620048 , 6930446 , 7454995 , 7891957 , 7781984 , 7894862 , 7071639 , 7322564 , 8008278 , 8175133 ] plt . scatter ( y , p ) plt . show ( ) See ya Oh, this is the result...

Matplotlib and Data for Python

Here we will see the code to show a simple graph with python and matplotlib inside of jupyter. The graph is about the growth of global population. As I wanted to use the 3.4.3 version of python (because I have installed the matplotlib libraries for that version) I used some magic syntax for jupyter... the %%script code at the start. %% script c:\python34_32bit\python.exe import matplotlib.pyplot as plt y = [1950,1970,1990,2010] p = [2.519, 3.692, 5.263, 6.972] plt.plot(y,p) plt.show() at the exectution of the code (in jupyter hit ctrl + enter) we will see this:

Virtualenv for different versions of python

Problem: I have the 3.6 version of python as default version. I want to use python 3.4 (because I have problems installing bpython due to the version of Visual c++ installed on my computer. I should disinstall Visual Studio 2015... but I choose this solution to avoid the need to reinstall it for different purposes). I thought: I could use virtualenv. I had it for python 3.4, but now that I have the 3.6 version I have to install it again. Go in the cmd (win+r)* and write: pip install virtual env *if you want to start the cmd from a dir, right click on the dir and choose from the menu... start the cmd from here. then I create a directory where to install my environment for the 3.4 version. We have to start virtualenv with the -p followed by the dir where is the version of python that we want to use and then the dir where we want to put the environment (p34 in this case): virtualenv -p c:\python34_32bit\python.exe p34 Now go in the p34/Scripts dir cd p34/Scripts t...

Using bpython instead of python

Hi! What is bpython? It's a fine way to use python instead of using the common interpreter of python. You can use python from the console (command line) in a more similar way to what you do with an editor like sublime with: - highlighted syntax - autompletion - autoindentation after : - etc. to install it (in linux, in windows omit the 'sudo') in the cmd: $ sudo pip3 install bpython See ya.