履歴: プログラミング/julia/グラフの書き方

各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 15 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます

日時タイトル文字数追加削除内容差分基準
2026/8/25 10:02:05プログラミング/julia/グラフの書き方 最新版16,566+1 -31表示差分—
2026/8/25 10:02:05プログラミング/julia/グラフの書き方 18,217+5 -1表示差分選択
2022/2/18 21:21:27プログラミング/julia/グラフの書き方 18,068+31 -0表示差分選択
2018/5/11 2:15:44プログラミング/julia/グラフの書き方 16,422+1 -1表示差分選択
2018/5/11 2:15:44プログラミング/julia/グラフの書き方 16,413+19 -11表示差分選択
2018/4/13 11:11:37プログラミング/julia/グラフの書き方 16,289+9 -0表示差分選択
2018/4/11 13:57:14プログラミング/julia/グラフの書き方 16,061+20 -1表示差分選択
2018/4/6 8:43:24プログラミング/julia/グラフの書き方 15,565+82 -15表示差分選択
2018/4/6 8:12:48プログラミング/julia/グラフの書き方 13,784+40 -18表示差分選択
2018/4/5 18:38:44プログラミング/julia/グラフの書き方 13,188+39 -24表示差分選択
2018/4/5 17:40:09プログラミング/julia/グラフの書き方 13,433+259 -29表示差分選択
2018/4/5 12:09:20プログラミング/julia/グラフの書き方 5,346+92 -0表示表示中選択
2018/4/4 8:59:33プログラミング/julia/グラフの書き方 3,560+83 -0表示差分選択
2018/4/3 16:11:57プログラミング/julia/グラフの書き方 656+15 -0表示差分基準
2018/4/3 12:17:57プログラミング/julia/グラフの書き方 321— —表示—選択

基準: プログラミング/julia/グラフの書き方 (2018/4/3 16:11:57) → 比較: プログラミング/julia/グラフの書き方 (2018/4/5 12:09:20)

@@ -1,5 +1,91 @@
[[プログラミング/julia]]
+* Plots を使う [#m6aac946]
+
+関数グラフの描画には [[Plots>http://docs.juliaplots.org/latest/]] というライブラリを使う。
+
+これは様々なグラフ描画ライブラリを julia から同一の API で使えるようにするためのラッパーライブラリ。
+
+実際の描画を行う Backend の描画ライブラリとして何を選ぶかによって、描画速度や仕上がりなどが結構変わってくる。
+
+** インストール [#k3a82351]
+
+バックエンドのライブラリがないと描画できないので、とりあえず GR, Plotly, PyPlot を入れておく。
+
+ LANG:julia
+ Pkg.add("Plots")
+ Pkg.add("GR")
+ Pkg.add("Plotly")
+ Pkg.add("PyPlot")
+
+ # 最新版を使うには
+ Pkg.checkout("Plots")
+
+** バックエンドライブラリ [#we87f61f]
+
+実際の描画を行うバックエンドライブラリはいろいろある。
+
+http://docs.juliaplots.org/latest/backends/
+
+例えばバックエンドライブラリとして GR を使うには、
+
+ LANG:julia
+ using Plots
+ Plots.gr() // Plots のバックエンドとして GR を使う
+ gr() // こう書いても同じ
+ // 引数としてオプションを渡せる
+
+などとする。
+
+2018春時点では、たぶん、有名なのは GR, Plotly, PyPlot の3つ。
+
+- GR : Plots.gr()
+-- 出力が svg になるので、印刷してもキレイ
+-- 点がたくさんあるとブラウザが固まる
+-- 普段使いにはこれがベスト?
+- Plotly : Plots.plotly()
+-- マウスでグラフの表示範囲などを調整可能
+-- 出力が svg になるので、印刷してもキレイ
+-- 点がたくさんあるとブラウザが固まる
+-- Gists 上などでは javascript が許可されないため表示できない
+-- jupyter notebook のリロードでエラーになり画像が表示されない場合がある
+-- 試行錯誤中は良いかもしれないけれど最終版としてはつらい
+- PyPlot : Plots.pyplot()
+-- 出力が png になるため、データ点の多いグラフでも Web ブラウザに負担がかからない
+-- ただ印刷などすると dpi 不足で画像が粗くなる
+-- PyCall の設定が必要(下記参照)
+-- データ点の多いグラフ専用?
+
+それぞれの表示はこんな感じ。~
+- Plotly の円グラフの表示がおかしい
+- PyPlot の円グラフが楕円になってしまっている
+
+&ref(test-julia-plots.png,,50%);
+
+GR のグラフは拡大してもキレイ
+
+&ref(test-julia-plots-gr.png,border,50%);
+
+PyPlot のグラフはぼやける
+
+&ref(test-julia-plots-pyplot.png,border,50%);
+
+Plotly のグラフはインタラクティブに編集できる。
+
+&attachref(test-julia-plots-plotly.gif,border,50%);
+
+でもブラウザ上でリロードするだけで、Plotly のグラフは
+
+ Javascript error adding output!
+ ReferenceError: Plotly is not defined
+ See your browser Javascript console for more details.
+
+などというエラーが出て表示されなくなってしまう。
+
+Gist 上でも無理。
+
+#gist(osamutake/da4856f49e025e4646214a0ce690ba06);
+
* このあたりを見る? [#v8a20489]
Plots/GR: グラフ package のおすすめ~
@@ -25,3 +111,92 @@
https://qiita.com/deaikei/items/b71c1ca2c4c2a2c37526
$ python3 -m pip install numpy plotly
+
+これとてもいいのだけれど、これを使った notebook のファイルサイズが非常に大きくなるみたい。
+
+簡単なグラフでも5メガバイトとか。
+
+で、gist へ保存ができなくなってしまった。
+
+どうしたらいいか、考え中。
+
+* PyPlot を使う [#k1b8dc14]
+
+matplotlib を使うので、
+
+ LANG:console
+ $ sudo python3 -m pip install matplotlib
+
+とすれば、python から使うのは簡単だった。
+
+#gist(13f0268cafbb92bd1b270503b1c738a5);
+
+julia から使うには、単に Pkg.add("PyPlot") しただけだと、
+
+ InitError: Failed to import required Python module matplotlib.
+
+ For automated matplotlib installation, try configuring PyCall to use the Conda.jl package's Python "Miniconda" distribution within Julia. Relaunch Julia and run:
+ ENV["PYTHON"]=""
+ Pkg.build("PyCall")
+ before trying again.
+
+ The pyimport exception was: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)
+
+ The Python package matplotlib could not be found by pyimport. Usually this means
+ that you did not install matplotlib in the Python version being used by PyCall.
+
+ PyCall is currently configured to use the Python version at:
+
+ python
+
+ and you should use whatever mechanism you usually use (apt-get, pip, conda,
+ etcetera) to install the Python package containing the matplotlib module.
+
+ One alternative is to re-configure PyCall to use a different Python
+ version on your system: set ENV["PYTHON"] to the path/name of the python
+ executable you want to use, run Pkg.build("PyCall"), and re-launch Julia.
+
+ Another alternative is to configure PyCall to use a Julia-specific Python
+ distribution via the Conda.jl package (which installs a private Anaconda
+ Python distribution), which has the advantage that packages can be installed
+ and kept up-to-date via Julia. As explained in the PyCall documentation,
+ set ENV["PYTHON"]="", run Pkg.build("PyCall"), and re-launch Julia. Then,
+ To install the matplotlib module, you can use `pyimport_conda("matplotlib", PKG)`,
+ where PKG is the Anaconda package the contains the module matplotlib,
+ or alternatively you can use the Conda package directly (via
+ `using Conda` followed by `Conda.add` etcetera).
+
+ ) <type 'exceptions.ImportError'>
+ ImportError('No module named matplotlib',)
+
+
+ during initialization of module PyPlot
+
+ Stacktrace:
+ [1] pyimport_conda(::String, ::String, ::String) at /home/osamu/.julia/v0.6/PyCall/src/PyCall.jl:609
+ [2] __init__() at /home/osamu/.julia/v0.6/PyPlot/src/init.jl:175
+ [3] _include_from_serialized(::String) at ./loading.jl:157
+ [4] _require_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:200
+ [5] _require_search_from_serialized(::Int64, ::Symbol, ::String, ::Bool) at ./loading.jl:236
+ [6] _require(::Symbol) at ./loading.jl:441
+ [7] require(::Symbol) at ./loading.jl:405
+ [8] include_string(::String, ::String) at ./loading.jl:522
+
+と言われ、PyCall を build する必要があった。
+
+ LANG:console
+ julia> Pkg.add("PyPlot")
+ julia> ENV["PYTHON"]=""
+ julia> Pkg.build("PyCall")
+
+ENV["PYTHON"]="" はシステムの python を使うためのおまじないっぽい?
+
+* GR を使う [#i952e995]
+
+グラフは svg で書かれるようで、クオリティーは高いけれど、
+あまり複雑なグラフを表示するとブラウザが固まる。
+
+
+* コメント・質問 [#xbcaa13f]
+
+#article_kcaptcha