ScipySparse - t-sakashita/rokko GitHub Wiki

Scipyのsparseパッケージ

MATLABと同様にspy関数で疎行列をプロットできる。

http://matplotlib.org/examples/pylab_examples/spy_demos.html

http://stackoverflow.com/questions/18651869/scipy-equivalent-for-matlab-spy

テキストファイルで行列を読み書き

http://hydrocul.github.io/wiki/numpy/ndarray-io.html

行列を読み込み描画

import numpy as np
import matplotlib.pylab as plt

A = np.loadtxt('matrix.txt')

A.shape

plt.spy(A)
plt.show()

Matrix Market形式の行列データのを読み込み描画

import scipy.io
import matplotlib.pylab as plt
A = scipy.io.mmread("output.mtx")
plt.spy(A, markersize = 0.5, precision = 0)
plt.show()

http://matplotlib.sourcearchive.com/documentation/0.99.1.2-3ubuntu1/classmatplotlib_1_1axes_1_1Axes_830a8ff5d70b0473941714c30855bd5a.html

フォントの埋め込み

matplotlib.use('pdf')
matplotlib.rc('pdf', fonttype=42)

参考: http://stackoverflow.com/questions/9054884/how-to-embed-fonts-in-pdfs-produced-by-matplotlib

Matrix Market形式の行列データを読み込み描画(MATLABの場合)

mmread.mを以下からとってくる。 http://math.nist.gov/MatrixMarket/mmio/matlab/mmiomatlab.html

A = mmread('~/build/rokko-clang/example/cxx/sparse/output.mtx')
spy(A)

pythonのmatplotlibとほぼ同様の描画結果が得られる。