Python: Difference between revisions

imported>Kjuvi
m Add missing semi-colon to the python3.withPackages my-python-packages
imported>JakobBruenker
added matplotlib example to explain how to use an interactive backend
Line 122: Line 122:
For example:
For example:
{{Commands|<nowiki>$ nix-shell -p gobjectIntrospection gtk3 'python2.withPackages (ps: with ps; [ pygobject3 ])' --run "python -c \"import pygtkcompat; pygtkcompat.enable_gtk(version='3.0')\""</nowiki>}}
{{Commands|<nowiki>$ nix-shell -p gobjectIntrospection gtk3 'python2.withPackages (ps: with ps; [ pygobject3 ])' --run "python -c \"import pygtkcompat; pygtkcompat.enable_gtk(version='3.0')\""</nowiki>}}
Or, if you want to use matplotlib interactively:
<syntaxhighlight lang=shell>
$ nix-shell -p gobjectIntrospection gtk3 'python36.withPackages(ps : with ps; [ matplotlib pygobject3 ipython ])'
$ ipython
</syntaxhighlight>
<syntaxhighlight lang=python>
In [1]: import matplotlib
In [2]: matplotlib.use('gtk3agg')
In [3]: import matplotlib.pyplot as plt
In [4]: plt.ion()
In [5]: plt.plot([1,3,2,4])
</syntaxhighlight>
You can also set <code>backend : GTK3Agg</code> in your <code>.config/matplotlib/matplotlibrc</code> file to avoid having to call <code>matplotlib.use('gtk3agg')</code>.
== External Documentation ==
== External Documentation ==


* [https://nixos.org/nixpkgs/manual/#python Python user guide in nixpkgs manual]
* [https://nixos.org/nixpkgs/manual/#python Python user guide in nixpkgs manual]