Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

Sunday, February 10, 2019

Python Matplotlib - showing or hiding a legend in a plot


When working with Matplotlib of visualize your data there are situations that you want to show the legend and in some cases you want to hide the legend. Showing or hiding the legend is very simple, as long as you know how to do it, the below example showcases both showing and hiding the legend from your plot.

The code used in this example uses pandas and matplotlib to plot the data. The full example of this is part of my machine learning example repository on Github where you can find this specific code and more.

Plot with legend
The below image shows the plotted data with a legend. Having a legend is in some cases very good, however in some cases it might be very disturbing to your image. Personally I think keeping a plot very clean (without a legend) is the best way of presenting a plot in many cases.
The code used for this is shown below. As you can see we use legend=True

df.plot(kind='line',x='ds',y='y',ax=ax, legend=True)


Plot without legend
The below image shows the plotted data without a legend. Having a legend is in some cases very good, however in some cases it might be very disturbing to your image. Personally I think keeping a plot very clean (without a legend) is the best way of presenting a plot in many cases.

The code used for this is shown below. As you can see we use legend=False
df.plot(kind='line',x='ds',y='y',ax=ax, legend=False)

Tuesday, February 07, 2012

Oracle Fusion customization platform

Sara Woodhull and Gustavo Jimenez recently gave a talk on how to do changes to Oracle E-Business Suite in a correct way. The talk was part of the ATG Live Webcast series which shows you how to make changes to a GUI that makes sense without the need to do much coding. When coding is needed examples will be used in the form of forms personalization and OA Framework Personalization’s


This presentation is also a great way to have a look into how the technology components of Oracle Fusion are used in Oracle e-Business suite and how they can help you and how you can build upon them to create customizations and custom solutions for customers with Oracle e-Business suite.

You can review the webcast at the oracle website and you can see the slides used below.

Personalize, Customize, and Extend Oracle E-Business Suite User Interface

Thursday, November 24, 2011

The future of computing is parallelism

predicting the future is always a tricky thing to do and many this is especially the case when you try to predict the future of computing as this is a field in which a lot of people do have an opinion. However, looking at where we currently stand and what the limits of physics are (as currently known) we can do some modest predictions.

As a statement: "the future of computing is parallelism".

If we look at the current speed of processors (per core) we see that the speed (frequency) is leveling out. Reason for this is that if you increase the frequency you will more leakage in your transistors which are on your chip. leakage is recorded to the outside world as heat. So if we where able to run the chips on a higher frequency we will see that the heat will increase up till a level which cannot be cooled in a "normal" way and against normal prices.

What chip manufacturers are doing to cope with this is issue is to build multi-core processors. Having multiple cores running on a acceptable frequency which is providing enough computational power to the system while keeping the heat within an acceptable range is the way forward. We can already see good examples of this in the AMD liano and the nvidia fermi (image below) many-core processors.


The new breed of processors will be many-core processors holding large number of cores. This will require new ways of developing software and programs. With many-core processors you will have the option (and the need) to run your programs over multiple cores to make full use of your hardware. To be able to do so one will have to consider parallelism when developing code. Developing parallel processes is another way of thinking which is currently not adopted by the majority of the developers simply because they can do without. However, as we are getting more and more data (bigdata), processes and computations are getting more complex and users are not willing to wait very long developers will have to think about parallel programming very soon.

You have some languages which are specially designd to cope with many-core processors, one example is CUDA which is developed by nvidia. You do however not need a special language, python is very well able to cope with it and java is also able to just like C for example. Issue is that developers have to start thinking about it and need to get familiar with it (in my opinion).

So what is the future of computing, parallel computing and many-core processes. Thom Dunning is explaining it in more detail in his "future of high performance computing" lecture for the National Center for Supercomputing Applications which you can watch below:

Tuesday, June 30, 2009

Milepost GCC machine learning

Developing code for embedded programs just got a little more easy. When you develop embed software most likely you will have to face things like performance and how much power the device will consume. Tuning such code can be very very complicated. You will have to study the device and your code. Developing a first beta of a embedded program which is not consuming to much power and is performing in a good fashion can take up to months.

Now IBM Research and Milepost Consortium have developed a new GCC open source machine learning compiler. The compiler will optimize your code and make shorter and better performing code so you can shorten your development cycle.

Besides having your compiler learn from your own devices and tricks you can also use the ctuning.org website to collaborate and upload code. This way you will get automatically input on how to improve your code.

If you are a developer on such code,….. or looking into the latest DARPA challenge you might want to give this a go.

Sunday, May 31, 2009

Python dictionary variables

A dictionary variable in Python is not that much different as a normal dictionary as you might have on your bookshelf. So first have a quick glimpse into the definition of a dictionary, accoording to wikipedia a dictionary is:

"A dictionary is a book or collection of words in a specific language, often listed alphabetically, with definitions, etymologies, pronunciations, and other information; or a book of words in one language with their equivalents in another, also known as a lexicon."

And this is somewhat the same as a dictionary variable we know in Python, it is a list with keys and a set of values. The keys are the index like the integer indices in a "normal" Python list variable. For example I want to make a dictionary containing all the employees per department like in the example below where you use the department name (dep0, dep1,.. in this case) as the key and the names of the people as the value. As you can see we first define the dictionary with a set of curly brackets. After that we define the key dep0 and the values attached to the key...than we take dep1.... dep2....

>>> empPerDep = {}
>>> empPerDep["dep0"]= "John","Carl","Vick"
>>> empPerDep["dep1"]= "Mark","Carl","Tom"
>>> empPerDep["dep2"]= "Tom","Bob","Jack"

Now we would like to do something with it so we can simply enter empPerDep to see what is in the dictionary however in a common situation most likely you will not want to print the entire dictionary.

>>> empPerDep
{'dep1': ('Mark', 'Carl', 'Tom'), 'dep0': ('John', 'Carl', 'Vick'), 'dep2': ('Tom', 'Bob', 'Jack')}

More likely you want to show something based upon a key like all the people in department zero. Which can be done with a statement like the one below:

>>> empPerDep["dep0"]
('John', 'Carl', 'Vick')

And in a case like this you will almost certainly want to go even more deeper and define which part of it you want to show, for example you want to show only the employee Carl, this can be done with a statement like the one below:

>>> empPerDep["dep0"][1]
'Carl'

This is all very usefull when you know what is where and you live in a very organized and structured world where everything is very predictable. However in normal world you will not be coding something is such a hardcoded way that if you want to print the name 'Carl' that you can hardcode empPerDep["dep0"][1] . You will have to make sure carl is in the dictionary and you have to find out where he is. We take a new example and use a phonebook application this time.

>>> empPhoneBook = {}
>>> empPhoneBook[12345]="Colin Aitken"
>>> empPhoneBook[12346]="Natalia A. Bochkina"
>>> empPhoneBook[12347]="Michael J Prentice"
>>> empPhoneBook[12348]="Sotirios Sabanis"
>>> empPhoneBook[12349]="Chris M Theobald"
>>> empPhoneBook[12350]="Bruce J Worton"

Now lets say we have to create a application around it, one of the things people will like to know is how many people in this university phonebook system are listed? You will be happy to see that also the len() function in Python will work on a dictionary.

>>> len(empPhoneBook)
6

now lets say you want an option where you will be able to check who has been assigned a certain number. What you can do is a empPhoneBook[76435] where 76435 is the number you want to have more details about. This is a valid option and will work as long as 76435 is a key in your dictionary. If it is not your code will generate a very nasty error.

>>> empPhoneBook[76435]
Traceback (most recent call last):
File "", line 1, in
KeyError: 76435
>>>

A better way to do this is to check before you try to retrieve. You can check if a key is in the dictionary by using the in option. This will give you a boolean back on which you can decide to try and retrieve the value.

>>> 12348 in empPhoneBook
True
>>> 76435 in empPhoneBook
False
>>>

Even do this is very useful you also want to do something like this the other way around. This is especially for a phonebook where you would like to search by name however the unique identifier is the phonenumber. So now we would like to know for example if "Colin Aitken" is in the dictionary so we do the following:

>>> "Colin Aitken" in empPhoneBook
False

Surprisingly this is giving a false, this is because it is looking into the keys not into the values. So if we want to check if the name is in the values we have to use empPhoneBook.values() instead of empPhoneBook which will only take the keys in account.

>>> "Colin Aitken" in empPhoneBook.values()
True

You will have to play around it little with dictionaries in Python to start loving them however when you do you will never give up that love to dictionaries again.

Monday, April 27, 2009

Python Format Specifier for Strings

When you are coding in python you can make use of the Format Specifier for Strings to format the output. In basic it is very simple to use when you like to manipulate your output. For example if we want to make "Your name is; Johan" we can do a print command as seen in the previous post however we can also do it a little different.

we can do a print "your name is: %s" % ("Johan") as seen in the example below

this will give us some more freedom in formating we now can for example manipulate the position of the first string which is represented by %s by adding a 10 between the % and the s which will make sure that there is space for a word of 10 characters. However he name Johan is 5 characters wide so it will leave space for 5 more characters.

you can also play around with adding a + or a - in front of the 10 so it will read +10 or -10. Just try it out and have some fun finding out how it works in detail.

Saturday, June 28, 2008

Authenticating to google finance API

The Google Finance and Google Data APIs teams are pleased to announce the release of a Google Data API for the Google Finance portfolios. I have already promised that I would spend some time on testing some things for this new API. So I now finaly found some time to check this new API. To be honest I had to check google finance first because I never made use of it.

The cool thing about the new API is that you will be able to download information from Google finance in a XML format so you will be able to use it in all kind of applications. Think about the possibilities of downloading this information to your application and maybe even use Google maps API and the Google chart API. You can make for example a very nice online application to show the world markets and how they behave…. Think about all those other cool things you always wanted to code in combination with stock information. You are now able to. Google, great news! Thanks!

In the upcoming days I will post a couple of posts about this new API but we will start at the beginning. How do you get access to data? Google finance is using your standard Google login information so you will not be needing a separate developers key or anything.

You can make use of two ways of authenticating to google finance. The first is “AuthSub proxy authentication” and the second one is “ClientLogin username/password authentication”. I will in this post not go into details about “AuthSub proxy authentication”, this I will save for an other post. I will now be discussing “ClientLogin username/password authentication”.

By making use of this option your “visitors” will have to provide their username and password for Google to you, so this can be the downside of this approach because they really have to trust you. However this is a side issue. After the user has provided you with the username and password you will have to request an authorization token (Auth) from google.

You will have to do a post to https://www.google.com/accounts/ClientLogin with the following parameters: Email, Passwd, service and source.

Email : The user's email address.
Passwd : The user's password.
Service : finance
Source : Identifies your client application. Should take the form companyName-applicationName-versionID.

The google API documentation states that you have to do a post with the content type application/x-www-form-urlencoded. On how you can get this from for example a php site you can take a look at ngoprek web weblog. There are also some other good examples on how to get the auth token from google.

Currently the API documentation is only showing examples in java in the Java client library so in my next post I will be trying to have a small example of a java web application which is interacting with the Google Finance API.