Reference http://blog.csdn.net/jcjc918/article/details/9354815
Http://blog.sina.com.cn/s/blog_6fb8aa0d0101qtt9.html
Http://stackoverflow.com/questions/3505831/in-python-how-do-i-convert-a-single-digit-number-into-a-double-digits-string
This evening tossing a bit of python, mainly to run through a Python GMM program. Accumulated some small knowledge of python.
1. Printing
(1).% character: The beginning of the token conversion specifier
(2). Convert flag:-Indicates left alignment, + indicates a positive sign before the value is converted, "" (white space character) to retain a white space before, and 0 for the conversion value if the number of digits is not enough. 0 padding
(3). Minimum field width: The converted string should have at least the width specified by the value. If it is *, the width is read from the value tuple.
(4). dot (.) Heel Precision Value: If the conversion is real, the precision value represents the number of digits after the decimal point. If the string is converted, the number represents the maximum field width. If it is *, then the precision will be read from the tuple
(5). string format conversion type
Conversion type meaning
D,i signed Decimal integer
o unsigned octal
U non-signed decimal
x hexadecimal without symbol (lowercase)
X hexadecimal without symbol (uppercase)
Floating point number represented by the e-scientific notation (lowercase)
The floating-point number represented by the E-scientific notation (uppercase)
F,f decimal Floating-point number
G If the exponent is greater than-4 or less than the precision value is the same as E, the other case is the same as F
G if the exponent is greater than-4 or less than the precision value is the same as E, the other case is the same as F
C Single-character (accepts integers or single character strings)
R string (convert any Python object using repr)
s string (convert any Python object using str)
2.plot, installation Matplot
Repeatedly installed and uninstalled several times finally put Matplotlib installed successfully, the main reference three links:
Link 1 http://blog.sciencenet.cn/blog-579770-738240.html
Link 2 http://www.open-open.com/lib/view/open1393488232380.html
Link 3 http://blog.csdn.net/yang6464158/article/details/18546871#comments
Link 4 http://www.lfd.uci.edu/~gohlke/pythonlibs/
Link 123 is a reliable installation process, the various packages required in this process can be found in link 4 (unofficial download, compare all).
Matplotlib installation of the official link for http://matplotlib.org/users/installing.html, no use. The following detailed documentation is adapted from the installation process for link 123 to backup.
Note: The version of each installer must be consistent, here are unified with windows,64 bit,python2.7 version (it is said that the python3.* series for some of the installation package is incompatible, so chose the older python2.7 version)!!!
1, pythonhttps://www.python.org/download/
2. Installation of matplotlib,http://matplotlib.org/downloads.html with Python counterpart version
3, for the standard version of Python, to use matplotlib, you need to install the NumPy module, see link 4
4, may also use the Msvcp.dll library, searches the net to add to the C:\windows\system32 directory by oneself.
If you run the import Matplotlib.pyplot as PLT at this point, the following error may be displayed:
Raise Importerror ("Matplotlib requiresdateutil")
Importerror:matplotlib requires Dateutil
It means you need dateutil.
5, installation dateutil,http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil
The error then occurs:
Raise Importerror ("Matplotlib requirespyparsing")
Importerror:matplotlib requires pyparsing
It means you need pyparsing.
6, installation pyparsing,http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyparsing
Error occurred after installation:
No Module name Six
Need to install SciPy
7, install SCIPY, see link 4.
Then copy the six.py Six.pyc six.pyo three files from the C:\Python27\Lib\site-packages\scipy\lib to the C:\Python27\Lib\site-packages directory.
Import Matplotlib.pyplot as PLT in the idle (Python GUI) can be solved!
8. Enter the following code without error:
Import Matplotlib
Import NumPy
Import scipy
Import pyparsing
Import Matplotlib.pyplot as Plt
9. Verify a simple example
Import Matplotlib.pyplot as Plt
Plt,plot ([i])
Plt.ylabel (' some numbers ')
Plt.show ()
The results are as follows
If you want to save, you can use Savefig () Note that the path must exist, not the new path.
3. How to convert a 1-bit number to a 2-bit string (http://stackoverflow.com/questions/3505831/ in-python-how-do-i-convert-a-single-digit-number-into-a-double-digits-string)
Quite simply, take advantage of some of the tricks in print printing.
Print "%02d"%a
And in the Python3,
"{0:0=2d}".format(a)