I'm trying to use HoloViews inside a python console instead of using it inside a jupyter/Ipython notebook.
To do that I tried to follow the example from the FAQ:
from holoviews import Store
renderer = Store.renderers['matplotlib'].instance(fig='svg', holomap='gif')
renderer.save(my_object, 'example_I', style=dict(Image={'cmap':'jet'}))
But apparently I don't have any backend available!:
$ python
Python 2.7.6 (default, Oct 26 2016, 20:22:54)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from holoviews import Store
>>> Store.renderers
OrderedDict()
Does anyone know if this is the intended behaviour or if my installation is broken?
I have HoloViews 1.6.2 (with pip) and Matplotlib 1.3.1 (from ubuntu)
You'll have to import the backend first. The notebook_extension does this automatically but when working with Renderers directly you'll have to manually import the backend like this:
from holoviews import Store
import holoviews.plotting.mpl
renderer = Store.renderers['matplotlib'].instance(fig='svg', holomap='gif')
renderer.save(my_object, 'example_I', style=dict(Image={'cmap':'jet'}))
We'll make sure to update the FAQ example.
Related
I am searching how can i use font-awesome icons to a Tkinter python application.
Here is what i tried:
https://fontawesome.com/icons/tree?style=solid
pip3 install fontawesome
Python 3.6.9 (default, May 23 2020, 00:01:58)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fontawesome as fa
>>> print(fa.icons['tree'])
>>>
I know that i must download icons - map (i do it in the past) but i don't find now how.
Thanks in advance
Edit: Same question before 26 days: FontAwesome with Python
If you want to see actual icons on your shell you need to install fontawesome's font on your computer and configure your terminal emulator to use this font.
Fontawesome the font is a font, but instead of just letters it also got icons.
fontawesome the python library is just dictionary with the icon's name as key and the character as value. But you can see the actual caractere only if you install Fontawesome the font.
From doc about interactive mode
With this code :
import matplotlib.pyplot as plt
plt.ioff()
plt.plot([1.6, 2.7])
plt.show()
show() call should block until I close the graph. But it doesn't, show() does not block execution. I can add some code to IPython shell while my figure still displayed.
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 6.5.0 -- An enhanced Interactive Python.
My backend is 'Qt5Agg'
I tested this code on another python env (from Cygwin): it works flawlessly.
You can turn off support for matplotlib via
Tools/Preferences/IPython Console/Graphics/Support for graphics(Matplotlib)/Activate support
I am trying to get the audio devices names from using PyQt4 framework in Python.
The code is as follows:
from PyQt4 import QtCore, QtGui, QtMultimedia
temp_list=()
x=()
for i in range(5):
temp_list=QtMultimedia.QAudioDeviceInfo.availableDevices(QtMultimedia.QAudio.AudioInput)
x=QtMultimedia.QAudioDeviceInfo.deviceName
print temp_list
print x
yet somehow I can't get the device names. Not too sure how to proceed from here.
It seems from your example code that you don't have much experience of using Python. I would advise you to work through some tutorials before proceeding any further. The Beginners Guide on the Python wiki is a good place to start.
I would also advise you to make full use of Python's interactive mode when trying to work out how the Qt APIs work. With the use of print, you can answer basic questions very quickly and easily. Here's an example session:
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtMultimedia
>>> devices = QtMultimedia.QAudioDeviceInfo.availableDevices(QtMultimedia.QAudio.AudioInput)
>>> print(devices)
[<PyQt4.QtMultimedia.QAudioDeviceInfo object at 0x00CC5C30>, <PyQt4.QtMultimedia.QAudioDeviceInfo object at 0x00CC5C70>]
>>> for device in devices:
... print(device.deviceName())
...
Intel(r) Integrated Audio
default
Just another way of doing it also, sounddevice lib is nice and easy to use !
py -m pip install sounddevice
import sounddevice as sd
def query():
a = sd.query_devices()
print(a)
query()
I'm trying to register the Firefox browser to run on Windows. According to the documentation for Webbrowser, "If the environment variable BROWSER exists, it is interpreted to override the platform default list of browsers, as a os.pathsep-separated list of browsers to try in order". I tried setting it, but it had no impact.
Z:\>SET BROWSER=C:\Program Files (x86)\Mozilla Firefox\firefox.exe %s
Z:\>python3
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (I
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import webbrowser
>>>
>>> webbrowser.open('http://google.com')
True
>>>
webbrowser.get("firefox") doesn't work either
How can I make webbrowser launch Firefox?
You might need to set static envionment viraibles, this you can do in the properties of my computer... Whether or not it will help is for you to figure out (worked over here..).
Another way to do this:
import webbrowser
webbrowser.get("open -a C:\\Program F~\\Mozilla Firefox\\firefox.exe %s")
webbrowser.open('http://google.com')
In python 2.7, by using
from __future__ import division, print_function
I can now have print(1/2) showing 0.5.
However is it possible to have this automatically imported at python startup ?
I tried to use the sitecustomize.py special module but the inport is only valid inside the module and not in the shell.
As I'm sure people will ask why I need that : teaching Python to teenagers I noticed that the integer division was not easy for them so we decided to switch to Python 3. However one of the requirement of the course was to be able to plot function and Matplotlib is pretty good but only valid for Python 2.7.
So my idea was to use a custom 2.7 installation...not perfect but I don't have a better idea to have both Matplotlib and the new "natural" division "1/2=0.5".
Any advice or maybe a Matplotlib alternative that is working on python 3.2 ?
matplotlib on python 3 is closer than you may think: https://github.com/matplotlib/matplotlib-py3; http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib.
Why not use PYTHONSTARTUP instead of sitecustomize.py?
localhost-2:~ $ cat startup.py
from __future__ import print_function
from __future__ import division
localhost-2:~ $ export PYTHONSTARTUP=""
localhost-2:~ $ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>> print("fred",end=",")
File "<stdin>", line 1
print("fred",end=",")
^
SyntaxError: invalid syntax
>>> ^D
localhost-2:~ $ export PYTHONSTARTUP=startup.py
localhost-2:~ $ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>> print("fred",end=",")
fred,>>>
No need to compile a new version of Python 2.x. You can do this at start up.
As you found, sitecustomize.py does not work. This is because the from __future__ import IDENTIFIER isn't an import. It flags the module to be compiled under special rules. Any module that uses those features must have the __future__ import, as well as the interactive console.
The following shell command will start the interactive console with division and print_function active:
python -ic "from __future__ import division, print_function"
You could alias to python (on linux) or set up a launcher to hide the extra stuff.
If you are using IDLE, the PYTHONSTARTUP script #DSM suggests should work there as well.
Note that these are not global throughout the interpreter, it only affects the interactive console. Modules on the file-system must import from __future__ explicitly to use the feature. If this is an issue, I suggest making a template to base work off of with all the needed imports:
# True division
from __future__ import division
# Modules
import matplotlib
# ... code ...
def main():
pass
if __name__ == "__main__":
main()
This may not be practical, but you may be able to compile a custom Python with the Python 3 division behavior backported. The problem with this is matplotlib might require the Python 2 behavior (although I'm not sure).