解决方法:在/etc/X11/xorg.conf添加:
Option "ignoreABI" "True"
EndSection
典型的Matplot例子:
import numpy as np
import matplotlib.pyplot as pltdef f(t):
return np.exp(-t) * np.cos(2*np.pi*t)t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), ‘bo’, t2, f(t2), ‘k’)plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), ‘r–’)
题目,坐标轴设置
最简单的就是通过title,xlabel和ylabel设置,比如
xlabel(”xxxx”, fontsize=18, color=”red”)
这里title是某个axis的title,如果希望整个figure有title,那么需要用suptitle() 函数,用法和title是一样的。
x和y轴的范围设定是通过
plt.axis([0, 6, 0, 20])
这就是表示x轴是0到6,y轴是0到20。也可以用xlim和ylim单独控制,比如
ylim( ymin, ymax )
当然还可以用yscale和xscale指定坐标轴的scale类型,分别是‘linear’ | ‘log’ | ‘symlog’,比如
xscale("log")
还可以通过yaxis.grid和xaxis.grid控制怎么显示网格,是否显示网格。grid的函数是这样的
grid(self, b=None, which=’major’, **kwargs)
Set the axis grid on or off; b is a boolean use which =
‘major’ | ‘minor’ to set the grid for major or minor ticks
如果用yaxis.grid (false),就表示不用显示y轴方向的网格。
有时候我们需要在坐标轴上放文字,比如在x轴上放置月份名称之类,这就需要xticks函数。其用法是比如
xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
这里,第一个参数表示放置位置,第二个是放置内容。
设置曲线特征
lines = plt.plot(x1, y1, x2, y2)
# use keyword args
plt.setp(lines, color='r', linewidth=2.0)
# or matlab style string value pairs
plt.setp(lines, 'color', 'r', 'linewidth', 2.0)
如果希望知道有哪些属性可以指定,可以传递对象给setp()函数,比如
In [69]: lines = plt.plot([1,2,3])In [70]: plt.setp(lines)
alpha: float
animated: [True | False]
antialiased or aa: [True | False]
…snip
具体能控制的属性参见这里。
文字处理
text()命令可以被用来放置文字在绝对坐标轴上,用法是
text(60, .025, r'$mu=100, sigma=15$', horizontalalignment='left', verticalalignment='top')
放置的东西前面加个r表示包括数学公式。具体能控制的属性可以参见属性列表。具体的数学公式和符号的表达方式参见这里。
这只是放置文字,还有一种需求是要求放置文字标注比如这种图:
这时候就要用到anotate()函数了,用法大概是这样的,
plt.annotate('local max', xy=(2, 1), xytext=(3, 1.5), arrowprops=dict(facecolor='black', shrink=0.05), )
第一个参数是要放置的文字,第二个参数是要指向的坐标,第三个是放置文字的坐标,最后一个是箭头属性。相关属性设置参见这里。
对于经常写公式的人来讲,可能latex的格式会感觉更加常用一点。这时候,可以在放置text之前先用
rc('text', usetex=True)
然后与文字有关的地方都用r”"来引用,比如
title(r"TeX is Number $displaystylesum_{n=1}^inftyfrac{-e^{ipi}}{2^n}$!",
fontsize=16, color='r')
画函数
plt.plot最简单的形式就是take一组列表数据
plt.plot([1,2,3])
此时plot自动将其认为是y轴的数据,x轴数据自动分配,相当于是
plt.plot([0,1,2],[1,2,3])
也就是说,对于plot,标准形式是
plt.plot([1,2,3,4], [1,4,9,16])
当然,后面可以跟控制表示形式的参数,比如
plt.plot([1,2,3,4], [1,4,9,16], ‘ro’)
就表示用红色点表示,而不是直线。参数默认是’b-’,表示蓝色直线。
plot还支持同时在一张图里面绘制多个图形,比如
import matplotlib.pyplot as plt
plt.plot(x1, y1, 'r--', x2, y2, 'bs', x3, y3, 'g^')
就可以用不同的形式绘制三条曲线。
画子图
用plt.subplot(xxx),第一个数字表示numrows,第二个表示numcols,第三个表示fignum。fignum的数量最高也就是numrows乘以numcols。
如果是想产生多个图,每个图包含几个子图,那用figure()来控制图的数量。
画直方图
用函数
hist(x, bins=10, range=None, normed=False, cumulative=False,
bottom=None, histtype='bar', align='mid',
orientation='vertical', rwidth=None, log=False, **kwargs)
具体用法参加这里。
画分布图
函数
scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None,
vmin=None, vmax=None, alpha=1.0, linewidths=None,
verts=None, **kwargs)
具体参数看这里,唯一一个不是很确定的是s的取值,我曾经估计是s值要和x和y的列表长度一样,也就是大概是点的个数?但具体画的时候发现不是这样,点的个数取决于x和y的列表长度。有待研究。
画Box Plot图
用matplot画Box Plot不知道有多方便,直接用函数
boxplot(x, notch=0, sym='+', vert=1, whis=1.5,
positions=None, widths=None)
你直接把一组数用x送进去,出来就是Box图。如果你想一个图表示多个Box,也很简单,让xappend多个list,出来的就是这些list的box图。一个例子如下
for attribute in iris[type].keys():
list = iris[type][attribute]
data.append(list)
subplot(2,2,count)
title(”Boxplot of %s” % type, fontsize=18, color=”red”)
xticks(arange(5),(”",”Sepal len”,”Sepal wid”,”Petal len”,”Petal wid”))
ylabel(”Value”)
boxplot(data,0,’gd’)
| 产品编码 | 产品名称 | 产品型号 | 保三年报价 | ||||
| MB871CH/A | Mac Pro | CPU:2.66GHz Intel Xeon;内存:3GB 1066MHz DDR3 ECC DIMM;硬盘:640GB SATA;显卡:NVIDIA GeForce GT 120, 512MB GDDR3 显存;光驱:18x SuperDrive | 21690 | ||||
| MB535CH/A | CPU:2×2.26GHz Intel Xeon;内存:6GB 1066MHz DDR3 ECC DIMM;硬盘:640GB SATA;显卡:NVIDIA GeForce GT 120, 512MB GDDR3 显存;光驱:18x SuperDrive | 27690 | |||||
|
i7930 技嘉EX58-UD3L OCZ4G套装 500G硬盘 索泰9800GT 银欣SilverStone Fortress2机箱 海盗船550w电源 三星P2370显示器
[GUID]i7 920 GA-EX58/UD3R DDRIII/2000 2GX3 GTX 285 mac os x10.6.4
主機板:技嘉 GA-EX58-UD5(X58-ICH10R)
處理器:英特爾 i7 930 2.8G(LGA1366) 顯示卡:艾爾莎 960GT 512B3 2DT RH(NVIDIA) 音效卡:瑞昱 ALC889A 網路卡:瑞昱 RTL8111D 主板:ASUS DSGC-DW服务器主板 3100RMB
CPU:Intel Xeon 5355 双四核处理器 2100RMB 显卡:XFX 9800GTX 512M独立显卡 960RMB 内存:DDR2 FDB 2GB*2 750RMB 硬盘:SATA II 500G 370RMB 光驱:先锋SATA DVD刻录 190RMB 机箱:服务器机箱 350RMB 电源:500W额定电源 580RMB 主机合计:10500 RMB
2、CPU:INTEL志强5550 双C (市场价约 2700元/颗)。
3、内存:金士顿 DDR3 2G/1066*6条 (市场价约 200元/条)。
4、显卡:蓝宝 HD4870 521M黄金版 (市场价约 1000元)。
2、开始安装苹果系统:
设置光驱启动放入光盘,引导后提示按F8.
按F8后输入: -V 联想3000G430 最高配置的 无线网卡 4310, 9300GS显卡, 2G内存, 成本3600样子.升级bios可以刷374字节,免费XP.vista.win7 完美黑苹果. cpu:E5200双核或者4核的Q8200(选哪个看你预算) I7 920 1900 台式:CPU Q8200 装hackintosh,最主要的就是主板和显卡的搭配,其他的东西,除了无线网卡基本上都兼容。 技嘉P43-ES3G,INTEL E6300,DDRII800 2G*2,N9500GT,WD500G 主板: 技嘉 EP45-UD3L GA-EP45-UD3L 刷bios后完美 用dell 的 490或690 准系统 490大概 1300元 690大概1600元 (含机箱 电源 主板) DVD刻录机 |
处理器 Intel Core i7 920 ( 2.67GHz 四核超线程 )
主 板 ASUS P6T ( Intel X58 芯片组 + CH10 )
内 存 GeIL 2×2 GB ( DDR3 1333 MHz 双通道 )
硬 盘 Seagate ST3500320AS ( 500GB S-ATA )
显 卡 NVIDIA Geforce GTX 295 ( 896MB )
光 驱 PHILIPS SPD2417T ( DVDRW 刻录 )
声 卡 ALC1200 ICH10 网 卡 RTL8111C
curl ftp://ftp.gnu.org/gnu/readline/readline-5.0.tar.gz | tar xfz - cd readline-5.0 ./configure cd shlib sed -e 's/-dynamic/-dynamiclib/' Makefile > Makefile.good mv Makefile.good Makefile cd .. make && sudo make install sudo rm /usr/lib/libreadline* sudo ln -s /usr/local/lib/libreadline* /usr/lib/ I got those from here, just FYI: http://tech.rufy.com/articles/2005/05/01/complete-fix-for-ruby-on-mac- os-x-10-4-tiger
The interweb seem to incline onpy2app when it come to deploying applications on mac. I’ve tried to make a single deployable .app file for my application for a long time trying to follow these instructions from ars technica. I’m not a hacker and just want to produce a deployable usable application for others to use. And it seems py2app from MacPorts wasn’t able to surmount the Snow Leopard’s 64-bit compatibility issue.
And then, I was slacking off while studying for my final and out of nowhere I found PyInstaller‘s explicit support for PyQt and its recent support for the mac. And after trying, almost everything works out without much of a kink. Credit goes to ChrisWayg who produced an amazingly complete and up-to-date set of instructions to follow. I’m merely telling how my application did using his instructions (April 2010) and hopefully doing my part to draw more attention to the excellent PyInstaller.
A PyQt application to help photographers apply custom watermarks in a manual but in an assisted way.
Uses:
All from MacPorts on Python 2.6.5, OSX 10.6.3.
PyInstaller is kinda special in that it’s not installed anywhere. It’s just a bunch of Python scripts that work on stuff in place. While you’re at it, read the manual.
svn co http://svn.pyinstaller.org/trunk ~/PyInstaller
Or put it somewhere you want.
Then you need to build the bootloaders. If you’re making PyQt applications, you probably have XCode already. Anyway, you need it.
cd source/linux python Make.py make cd .. python Configure.py
So far, PyInstaller has a problem of not showing your application at the front when you run it. You can fix it in your own code by adding
form.raise_()
right after
form.show()
with “form” being whatever you called your instance of MainWindow().
Like with py2app, you gotta first make a “spec file”.
python Makespec.py --onefile /path/to/YourApplication.py
This will make a YourApplication/YourApplication.spec file in your PyInstaller folder.
To make it work on mac, add
import sys if sys.platform.startswith("darwin"): app = BUNDLE(exe, appname='WhateverYouWantToCallIt', version=1)
at the bottom.
For my application, it made 70 files inside the .app file on default. –onefile makes it more neat and 3 times smaller in size! but it does make it a bit slower. If you care to make it as fast as possible, leave out that option but you have tofix a bug yourself.
Finally, build the application!
python Build.py YourApplication/YourApplication.spec
This will make your application and leave a YourApplication.app in your PyInstaller folder.
Put your own nice icon on the application. Copy your graphic, right-click your application and choose Get Info, click the icon and paste the graphic.
Open the content of your application, open Contents/Info.plist, uncheck “Application is background only” and save. If you’re using a plain text editor, change LSBackgroundOnly to false.
There is only one last problem to deal with on mac. You have to copy the qt_menu.nib file.
locate qt_menu.nib
to find it. If you use MacPorts, it’s probably somewhere like /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib
Copy it to your YourApplication.app/Contents/Resources
Boom, you can double click your application and it will run!
Ok, one last problem, I swear. When you run, it shows 2 icons on the dock… pretty ugly. This hack can fix it, but it’s not perfect as it leaves junk on your computer. Hopefully PyInstaller can address it soon.
The program is beautiful! You don’t have to worry about your Python plug-ins, your 64-bitness, anything (mostly). It just works. I have yet to figure out how to make 32-bit binaries on 64-bit systems and how to make upx work properly to reduce executable size. I’m currently running at 32mb for an application that really should be 1mb. But then again, it’s packaging a whole new GUI framework that doesn’t exist on the target computer with the application. Consider Skype (yes, it’s infinitely more complex than my thing), it is still 43mb.
If you have a pre-setuptools version of py2app installed, you must first remove it before installing (you may have to run the interpreter with sudo, depending on how and where py2app was originally installed). There are three paths that need to be removed: py2app and py2app.pth in your site-packages folder, and thepy2applet script which may be in /usr/local/bin/ or otherwise in the bin directory belonging to the Python framework that was installed.
Here is a Python script that should find these three paths and remove them if they exist (you may have to use sudo):
#!/usr/bin/env python
import os, shutil
from distutils.sysconfig import *
py2app = os.path.join(get_python_lib(), 'py2app')
import shutil
if os.path.isdir(py2app):
print "Removing " + py2app
shutil.rmtree(py2app)
if os.path.exists(py2app + '.pth'):
print "Removing " + py2app + '.pth'
os.unlink(py2app + '.pth')
for path in os.environ['PATH'].split(':'):
script = os.path.join(path, 'py2applet')
if os.path.exists(script):
print "Removing " + script
os.unlink(script)
To install py2app using easy_install you must make sure you have a recent version of setuptools installed (as of this writing, 0.6b4 or later):
$ curl -O http://peak.telecommunity.com/dist/ez_setup.py $ sudo python ez_setup.py -U setuptools
To install or upgrade to the latest released version of py2app:
$ sudo easy_install -U py2app
To install py2app from source, simply use the normal procedure for installing any Python package. Since py2app uses setuptools, all dependencies (includingsetuptools itself) will be automatically acquired and installed for you as appropriate:
$ python setup.py install
If you’re using a svn checkout, it’s recommended to use the setuptools develop command, which will simply activate py2app directly from your source directory. This way you can do a svn up or make changes to the source code without re-installing every time:
$ python setup.py develop
The setup.py template has changed slightly in py2app 0.3 in order to accommodate the enhancements brought on by setuptools. Old setup.py scripts look like this:
from distutils.core import setup
import py2app
setup(
app=["myscript.py"],
)
New py2app scripts should look like this:
from setuptools import setup
setup(
app=["myscript.py"],
setup_requires=["py2app"],
)