Set locale to cartopy ticker - ticker

I was wondering and searching on the docs: is there a way to set the locale, for example, to use commas instead of points as separators for decimals in cartopy ticklabels?
In matplotlib it can be done, but it doesn't apply to cartopy.mpl.ticker's LongitudeFormatter and LatitudeFormatter.
Maybe it's something for the developers to add in newer versions?

Nothing too special about the LongitudeFormatter and LatitudeFormatter, they are just specialised Formatters.
So, the gridlines object has properties 'xformatter' and 'yformatter', which have a 'set_useLocale' method.
This worked for me...
>>> ax = plt.gca()
>>> gl = ax.gridlines(draw_labels=True,
... xlocs=[-120.5, -50.8, 30.7, 134.2, 157.8])
>>> gl.xformatter.set_useLocale(True)
>>> plt.show()
BUT you do have to have the machine locale set to start with.
In order to get "," numeric seperators, I started with :
$ export LC_NUMERIC="it_IT.UTF-8"
$ python
I don't know much about it, but I think you can't change this dynamically through the Python interface, it needs to be in the calling environment
-- see Setting Python locale doesn't work

Related

How to use kde_kws parameters for seaborn.histplot()?

I am trying to use sns.histplot() instead of sns.distplot() since I got the following message in colab:
FutureWarning: distplot is a deprecated function and will be removed
in a future version. Please adapt your code to use either displot (a
figure-level function with similar flexibility) or histplot (an axes-level function for histograms).
Code:
import pandas as pd
import seaborn as sns
df = sns.load_dataset('tips')
sns.histplot(df['tip'], kde=True, kde_kws={'fill' : True});
I got an error when passing kde_kws parameters inside sns.histplot():
TypeError: init() got an unexpected keyword argument 'fill'
From the documentation kde_kws= is intended to pass arguments "that control the KDE computation, as in kdeplot()." It is not entirely explicit which arguments those are, but they seem to be the ones like bw_method= and bw_adjust= that change the way the KDE is computed, rather than displayed. If you want to change the appearance of the KDE plot, the you can use line_kws=, but, as the name implies, the KDE is represented only by a line and therefore cannot be filled.
If you want both a histogram and a filled KDE, you need to combine histplot() and kdeplot() on the same axes
sns.histplot(df['tip'], stat='density')
sns.kdeplot(df['tip'], fill=True)

PyGtk3 and Gettext - problem choosing the language at run-time

Long story short, when I thought the strings would be translated, nothing happens.
I have a PyGtk application and a module where I store all the strings that I want to be translated in the following way:
'''
Strings module.
'''
....
CANCEL_BUTTON_TEXT = _("Cancel")
BACK_BUTTON_TEXT = _("Back")
....
And so on. So then they are used from other modules like:
'''
View module.
'''
import strings
# Usage example
button.set_label(strings.CANCEL_BUTTON_TEXT)
button.set_tooltip(strings.TOOLTIP)
window_title.set_title(strings.WINDOW_TITLE)
...
I have created the necessary .mo files. This is the jerarquy I have:
/locales
/es
LC_MESSAGES
base.mo
base.po
/en
LC_MESSAGES
base.mo
base.po
base.pot
As the documentation says (https://docs.python.org/3/library/gettext.html), in my main.py I have the following lines:
import gettext
gettext.install('myapplication')
es_lang = gettext.translation('base', localedir='locales', languages=['es'])
en_lang = gettext.translation('base', localedir='locales', languages=['en'])
es_lang.install()
Then, in my application I have a button, that when is pressed, the following line is executed:
en_lang.install()
But the spanish language is still used on the widgets. Could anyone help me out?
So, what I was doing wrong is I was translating the strings but I wasn't updating the GTK Widgets labels, among other things.
The way I solved this was:
i) Created a class where I put all the strings I want to translate when the user selects a language. That class is the only one to import the gettext module.
ii) When the user selects a language, a method of that class is called and it translates all strings to that language.
iii) Another method outside that class updates all labels and widgets that use those strings.

Xojo MacOs Vs. Windows? EndOFLine issue

So I created a program on Xojo(MacOS) that parses paragraphs using EndofLine. However, when I run it on a Windows operating system it doesn't parse it at all. Does Window operating systems recognize EndofLine or Chr(10)+Chr(13) in Xojo?
Xojo's EndOfLine constant is indeed different depending on the platform you use it for.
You have two choices of dealing with this:
Explicitly use a platform specific constant:
EndOfLine.Windows gives CR+LF
EndOfLine.Unix gives LF
The better way, especially if you import data from outside the program, e.g. when reading from a file or from a network socket, is to normalize the line delimiters for your internal use, like this:
normalizedString = ReplaceLineEndings (importedString, EndOfLine)
Now, you can use EndOfLine with normalizedString, e.g. to split it into single lines:
dim lines() as String = normalizedString.Split (EndOfLine)
When you write this string back, you'll automatically have it in the system's format already.
However, when you export your text to a system where you know it expects them in a certain format, convert them back to that format like this:
// E.g, if you export them for a Mac:
outputString = ReplaceLineEndings (internalString, EndOfLine.Unix)
EndOfLine is always platform dependent, so in case of Windows, its value is chr(13)+chr(10), while on macOS it's chr(10). You can reach these platform-specific values directly by using EndOfLine.Windows and EndOfLine.OSX.
To normalise the line endings in a string, you can use the ReplaceLineEndings() function.

How to print right-to-left report on odoo 8

I created a report in odoo 8 using RML, everything is good. but when i print the report, caracteres are printed from left to right. I tried with drawRightString but nothing does appears on the PDF.
I used openerp-rtl module but I noticed no changes.
What can i do to print it in RTL mode.
Generally people working on Right to left text on Arbic Language.
so in this case you just install the below python-bidi package :
https://pypi.python.org/pypi/python-bidi/
python-bidi package is helpful to set the Pure python implementation of the BiDi layout algorithm.
And also add the bidi directory in your OpenERP report dir and use the get_display(string) method for making your sting convert into the arbic formate and also use with the arabic_reshaper class
You can do some thing like
import arabic_reshaper
from bidi.algorithm import get_display
def get_arabic_string(string):
reshaped_text = arabic_reshaper.reshape(string)
bidi_text = get_display(reshaped_text)
return bidi_text
Just need to use the get_arbic_string function in your rml file and set it on rml and pass the sting as arbic formate.
just check another source :
pyfribidi for windows or any other bidi algorithm

return information using pexpect

I am learning how to use pexpect and i had a question. I am trying to find the version number of a remote server and based on that version number I want to choose the right driver number. I am not entirely sure how should I go about doing this. Something along the lines of a getline function. Let me know if there are any functions I could use
The child .before and .after properties contain the stdout before resp. after the matched expectation.
import pexpect
child = pexpect.spawn('cat /etc/issue')
child.expect('Ubuntu.*')
print(child.after)
Which of the commands requires input? If it is the driver installation you could use fabric & fexpect:
from ilogue.fexpect import expect, expecting, run
output = run('get-system-version')
prompts = []
prompts += expect('Which driver version do you want to install?',output)
with expecting(prompts):
run('install-driver-command')

Resources