matplotlib style library not updating when .mplstyle files added/deleted - python-2.7

I'm trying to create my own matplotlib stylesheets but Python doesn't detect them. Even worse: when I moved one of the five default stylesheets (ggplot.mplstyle), Python kept reporting it was availabe.
I tried to reload the entire module but to no avail:
import matplotlib
reload(matplotlib)
from matplotlib import style as style
plt = matplotlib.pyplot
print plt.style.available
just keeps returning
[u'dark_background', u'bmh', u'grayscale', u'ggplot', u'fivethirtyeight']
How can I force a "refresh" of these styles?
P.s. I'm not a Python expert.

Just in case someone else stumbles on this post, this issue was reported and resolved here:
https://github.com/matplotlib/matplotlib/issues/3601
Basically, the style library looks for files in a subdirectory of the matplotlib config directory. On linux/osx system, this would be something like ~/.matplotlib/stylelib/<my-custom-style>.mplstyle.
Also, as #tcaswell suggested in comments, loading is done at import time, so style files added or edited after import will not work without a call to plt.style.reload_library().

Related

Multiple Transforms for VSCode Snippet

I've got a few snippets set up and working as I would like to, but I'm having a hard time getting one snippet to work where I believe I will need to have multiple transforms occur?
Essentially I have a TypeScript Interface defined for one of my components.
i.e. IRadioButtonListProps.ts which is inside of an Interfaces folder. The Interfaces folder has a sibling folder named Theme containing an interface named IRadioButtonListTheme.ts
Inside of IRadioButtonListProps I'm trying to stub out the entire interface. The snippet I currently have stubs out the interface like...
import * as React from 'react';
import IRadioButtonListPropsTheme from '../Theme/IRadioButtonListPropsTheme';
export interface IRadioButtonListPropsProps {
...props...
}
export default IRadioButtonListPropsProps;
The import line inside of the snippet is...
"import I${TM_FILENAME_BASE/(.*)\\..+$/$1/}Props from './Interfaces/I${TM_FILENAME_BASE/(.*)\\..+$/$1/}Props';"
What I'm trying to have happen and can't seem to figure out is how to also remove the word "Props". So instead of import IRadioButtonListPropsTheme... I would get import import IRadioButtonListTheme....
At the same time, I want to remove all extensions, including those of the form *.abc.abc ("two" extensions) and *.abc (one simple extension).
Is this possible?
It isn't crystal clear what you what but try:
"import ${TM_FILENAME/((\\w*)Props)*?(\\..*)/$2/}Theme from './Interfaces/${TM_FILENAME/((\\w*)Props)*?(\\..*)/$2/}Theme';"
which results in:
import IRadioButtonListTheme from './Interfaces/IRadioButtonListTheme';
from IRadioButtonListProps.ts
and
import CheckboxListTheme from './Interfaces/CheckboxListTheme';
from CheckboxListProps.test.tsx
[Edit] Here is a simpler version which I think also works:
"import ${TM_FILENAME/(Props)*?(\\..*)//}Theme from './Interfaces/${TM_FILENAME/(Props)*?(\\..*)//}Theme';"
match any "Props", if any, replace with nothing.
match from first \. to end of filename, replace with nothing.

python tkinter using variables across files,?

I have been playing with Tkinter in Python 2.7, and just ran across something that SHOULD be a bug, but isn't and the program seems to work OK still.
To make my program more manageable, I have split it into separate .py files.
One file (called globs.py) is a list of global variables in the form
global var_1
global var_2
...
Then I import globs into my other files.
In another file I can set the variable, thus...
import globs
globs.var_1 = "some value"
In a third file I can use it..
import globs
if globs.var_1 == "something":
...
So far, all is as expected, but...
I just found out if the variable is NOT mentioned in the globs.py file at all, the program still seems to work OK.
Is this intended behavior? Any other programming language would give a 'variable not found' error.
If it is intended, why should I even setup any variables in globs.py?
What are the drawbacks?
Thanks, Mark.

Can't inline Bokeh in IPython

I have the latest Bokeh and IPython installed, and I try running the following:
(all of these imports are relevant later on in the code)
import pandas as pd
import datetime
import matplotlib.pyplot as plt
import itertools as itt
import bokeh.plotting as bk
bk.output_notebook()
xs = [0,1,2,3,4,5]
ys = [x**2 for x in xs]
p.line(xs, ys, line_width=2)
p.circle(xs,ys)
bk.show(p)
After running these 2 cells, I get:
Javascript error adding output! ReferenceError: Bokeh is not defined
See your browser Javascript console for more details.
So, I run the console and see this:
ReferenceError: Bokeh is not defined Stack trace: #http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302 line 4 > eval:1:1 .globalEval#http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:4231 .domManip#http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:21389 .append#http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:5:18980 OutputArea.prototype._safe_append#http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:414:13 OutputArea.prototype.append_display_data#http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:534:13 OutputArea.prototype.append_output#http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:320:13 OutputArea.prototype.handle_output#http://localhost:8888/static/notebook/js/outputarea.js?v=20150304125302:234:9 CodeCell.prototype.get_callbacks/<.iopub.output#http://localhost:8888/static/notebook/js/codecell.js?v=20150304125302:456:21 Kernel.prototype._handle_output_message#http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:997:13 .proxy/i#http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 Kernel.prototype._handle_iopub_message#http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:1024:13 Kernel.prototype._finish_ws_message#http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:866:17 .proxy/i#http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 deserialize#http://localhost:8888/static/services/kernels/serialize.js?v=20150304125302:60:13 Kernel.prototype._handle_ws_message#http://localhost:8888/static/services/kernels/kernel.js?v=20150304125302:857:9 .proxy/i#http://localhost:8888/static/components/jquery/jquery.min.js?v=20150304125302:4:5486 outputarea.js:416
Before seeing this, bk.show(p) displayed a distorted plot, saying "Hello Word", but all the buttons were deformed.
matplotlib works fine.
This issues was addressed in https://github.com/bokeh/bokeh/issues/2024 which moved the code that loads BokehJS into output_notebook instead of just trying to do it when bokeh is imported. However, I would still recommend putting bk.output_notebook in its own ipython cell with nothing else. I am going to update the documentation to reflect this recommendation soon. The issue is that Bokeh uses IPython's "publish" mechanism to load itself, and if you put other things in a cell that also have output, it can interfere with that. Thats just the way IPython notebook works, there's not really anything else to do but to suggest putting output_notebook on its own, so it is output is guaranteed to be correct.
So, i restarted the system a few times, and started a new notebook, and suddenly everything works. i'm guessing the issue was with one of the imports, but i'm not 100% sure. now everything works perfect.
The problem here is that Javascript function loaded in IPython.core.display, ommit it and re-run your code.

Can ember-cli import json and other non-JS files?

Given that ember-cli uses ES6 modules syntax to import other JavaScript files, is it also possible to use this same syntax to import non-JavaScript files, such as JSON files or other text files?
Assume I have a JSON file named "foo.json" in my current directory. How could I import the contents of that file into a variable within my current JavaScript file? I've tried, without success, several variations of:
import foo from 'foo.json';
if (typeof foo === 'object') {
// Success
} else {
// import failed
}
Is it possible to import non-JavaScript files into the current file using the import statement or any other means?
No it's not. The ES6 modules syntax to import stuff also needs the requested object to be properly exported, which your json-files or text-files won't be. Also, since we don't really have ES6 in browsers yet, all those nifty statements are converted to commonjs-modules when building your project.
As I see it you have two options for this.
Putting the files in your public-folder and load them via ajax is the simple solution though not very elegant.
The cool option would be to add a preprocessor of your own that wraps your json-files in a proper export-statement as a build-step. That would be quite a lot of more work though and might require some deep diving into ember-cli and broccoli to attach it at the right time.
Yes, ember-cli can import JSON and non-JS files as long as you have the proper plugin.
This one allows the import of JSON files:
https://github.com/IvyApp/ember-cli-json-module
... and this one works for YAML: https://github.com/joankaradimov/ember-cli-yaml-module.

Can't save figure as .eps [gswin32c is not recognized]

I'm using Enthought Canopy with PyLab(64-bit). For my report I need to use Latex (XeLaTex) and the plots are done with matplotlib.
To have an first idea I just copied the second example from http://matplotlib.org/users/usetex.html and compiled it. It looks fine and I can save it as a normal png without problems. However if i try to save it as .eps or.ps it does not work and an error appears:
invalid literal for int() with base 10: "
Additionaly in the Pylab shell it shows:
'gswin32c' is not recognized as an internal or external command, operable program or batch file'.
If I save it as .pdf I have no problems except the text is all black instead of being red and blue. This is a problem because in my plots I have two axes and I need them colorized for better readability.
If I then try to delete some lines from the example given (all text) I still cannot save it as .eps nor .ps. I can't figure out the problem and all the other topics related to this have not given me an insight. So I really need your help because I can't use .png for my report.
Thank you in advance!!!
I finally managed to solve this problem. It might look weird but maybe other people can benefit from it.
The solution might depend upon the software you use. I use Enthought Canopy (Python) and MikTeX 2.9 under W8 64bit.
If you want to output .ps and .eps files with matplotlib using the 'text.usetex': True option then you will encounter the problem posted above.
Solution:
Download and install Ghostscript (32bit) from http://www.ghostscript.com/download/gsdnld.html.
Download ps2eps-1.68.zip from http://www.tm.uka.de/~bless/ps2eps. The proceeding is given in the manual, however I like to point out the part with the environment variables. In this last step you need to go to Control Panel --> System --> Advanced system settings. Then click on the header 'Advanced' and on the bottom of the window you see 'Environment Variables' on which you click. Then you use the 'New'-Button for User Variables for USERNAME. Then you type in as variable name 'ps2eps' and for variable value you type in the actual path where you have saved the ps2eps.pl file. In my case this is 'C:\Program Files (x86)\ps2eps\bin\'. You can check if you type 'ps2eps' in the command-window.
Download xpdfbin-win-3.03.zip from http://www.foolabs.com/xpdf/download.html. You only need the file 'pdftops.exe'. However I could not assign a path like in step 2. I solved this by putting the 'pdftops.exe' in the MikTeX 2.9 folder. The exact location for me was 'C:\Program Files\MiKTeX 2.9\miktex\bin\x64'.
I was then able to save figures as .ps and have no more any error messages. Remember to use the settings proposed on http://matplotlib.org/users/usetex.html under 'postscript options'.
In myself used the following settings:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import matplotlib as mpl
mpl.rc('font', **{'family':'serif', 'serif':['Computer Modern Roman'],
'monospace':['Computer Modern Typewriter']})
params = {'backend': 'ps',
'text.latex.preamble': [r"\usepackage{upgreek}",
r"\usepackage{siunitx}",
r"\usepackage{amsmath}",
r"\usepackage{amstext}",],
'axes.labelsize': 18,
#'axes.linewidth': 1,
#'text.fontsize':17,
'legend.fontsize': 10,
'xtick.labelsize': 13,
#'xtick.major.width' : 0.75,
'ytick.labelsize': 13,
'figure.figsize': [8.8,6.8],
#'figure.dpi': 120,
'text.usetex': True,
'axes.unicode_minus': True,
'ps.usedistiller' : 'xpdf'}
mpl.rcParams.update(params)
mpl.rcParams.update({'figure.autolayout':True})
(whereas many of the params are just for my own purpose later in the plots)
As a beginner I am not well informed about the dependence from the 'backend' used if you are running a script from your python console. I however used this without any --pylab settings in before and I do not know if one needs to switch the backend manually if he is working already in a console with a specific matplotlib backend.
I had the same problem and my problem was a font adjustment in the python code that is :
from matplotlib import rc
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
rc('text', usetex=True)
when I remove this iit works fine and now i can save eps.
So be sure that any shortest working example is working for you or not then check the font and other style edits in your code. This may help.