
上手な人には、「何でそんな事をワザワザ」と思うかもしれないが、Matplotlibの使い方を知らない人には、分からないのでメモしておく。
自分が、こんな感じで解説が欲しかったし。
Matplotlibの公式サイトで、broken axisとして紹介されているグラフの描き方が、日本語ではないのでよく分からないし。
Matplotlibのギャラリーには、broken axis のグラフを描くためにこういう風にかいてあるけど、
いろいろなコマンドを組み合わせて使っているから、何をすれば、にょろにょろになるのか、検討が付かない。
自分は、ワンタッチで画像が欲しい。
Broken_axisコマンドとかあったら、たとえ引数が多くても、それを使いたい。
でも、そんなものはない。
要素ごとに確認していく。
import matplotlib.pyplot as plt
f, (ax, ax2) = plt.subplots(2, 1)
f.show()

subplotが基本構造ですよ。
subplotは前回描いたが、
グラフを分割して描いてくれる。
ax1 = plt.subplots(2, 1, 1)
ax2 = plt.subplots(2, 1, 2, sharex=True)のようにバラバラでもいいが、まとめて書くには、
f, (ax1, ax2) = plt.subplots(2,1)とか。
上記の画像の様に、1画像に2グラフ(以上)縦に並べて描く時は、x軸が同期している事が多い(もしくは、横に並べる場合はy軸が同期していることが多い)。
だから、sharexがsubplotの中に用意されていて、
f, (ax1, ax2) = plt.subplots(2,1, sharex = True)
とすると、片方のグラフにxが100とか、-100とかが入って、自動的にグラフの大きさが調節された時に、ax1, ax2が同時に動いてくれる。
Trueの反対はFalse。Boolean型の変数。bool型。
import matplotlib.pyplot as plt
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
f.show()

sharexすると、subplot間で、x軸が共有されます。
xがshareでsharexって事なんでしょう。
shareyもあるし。
sharexが機能しているところ
"""
sharex01
"""
import matplotlib.pyplot as plt
import numpy as np
f, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
theta1 = np.linspace(0,np.pi,1001)
y1 = np.sin(theta1)
ax1.plot(theta1, y1)
ax1.set_ylim(-1, 1)
ax2.set_ylim(-1, 1)
#plt.xticks(x, label, fontsize = 7)
plt.show()
"""
sharex02
"""
import matplotlib.pyplot as plt
import numpy as np
f, (ax1, ax2) = plt.subplots(2, 1, sharex=True)
theta1 = np.linspace(0,np.pi,1001)
theta2 = np.linspace(0,np.pi,1001)*2
y1 = np.sin(theta1)
y2 = np.sin(theta2)
ax1.plot(theta1, y1)
ax2.plot(theta2, y2)
ax1.set_ylim(-1, 1)
ax2.set_ylim(-1, 1)
#plt.xticks(x, label, fontsize = 7)
plt.show()
sharex01

sharex02

別のグラフ扱いであるはずのax1も、ax2にプロットされたデータと同じxになるように伸縮する。
まあ、Broken axisの時には、ax1もax2も同じデータを載せるので、横に伸び縮みもしないはずなので、あまり意識しない部分ではありますが、重要なので一応。
import matplotlib.pyplot as plt
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
f.show()

spines[位置].set_visible(False)
で位置の所には、left, right, bottom, topのどれかを、文字列として入れる。
文字列としていれるってことは、
["top"]とか['left']って囲まなきゃいけないんだよ。pythonでは。
英語で言うとstringだし、str型の変数ともいう。
Falseがなんで文字列みたいな扱いじゃなくてもいいのかというと、文字列じゃないから。
文字列なら""と囲っとかないとだめだし、False何て変数は定義していない。
組み込み関数でもない。
変数bool型は、TrueかFalseをもつ型。
intは1とか-10とか。(整数:integer)
uintは、マイナスをとらない1とか10(unsigned int)最近、画像処理してて知った。
要るよこれ。RGBの値がマイナス行ったら変だよ。
floatは0.1とか。(浮動小数点)
話を元に戻すと、
上の画像には、何か変なのが残ってしまいました。
tickってやつが残っている。
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_top()
ax2.xaxis.tick_bottom()
f.show()

上下にぶち抜いてやったぜ。
ただ、正直な所、ぶち抜く必要は無いかも。
import matplotlib.pyplot as plt
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
ax.xaxis.tick_top()
ax2.xaxis.tick_bottom()
f.show()

これも、その一個前のグラフも、ラベルが付いてしまっている。
ax.tick_params(labeltop='off')
で確実に落とす。

ここも参考になる。
http://stackoverflow.com/questions/12998430/remove-xticks-in-a-matplot-lib-plot
こんな感じに3段だって可能。
f, (ax, ax2, ax3) = plt.subplots(3, 1, sharex=True)
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax3.spines['top'].set_visible(False)
ax.xaxis.tick_top()
ax2.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')
ax3.xaxis.tick_bottom()
ax.tick_params(labeltop='off')
plt.show()


いよいよデータを載せていく
データには、sinカーブの前半分を、数乗して使う。
数乗って言い回しはないのだろうか。
書いちゃうけど。
1乗だと、sinカーブの前半分。

数乗すると、既に大きい所はより大きく、小さい所はより小さく変化していく。
subplotを出した時点で分かるとは思うけど、下のグラフと上のグラフのプロットは、同じものではない。
下のデータの値が大きすぎると、上の方まではみ出てくるとか、そういう仕組みではない。
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,1001)
theta = np.linspace(0,np.pi,1001)
#y = np.sin(theta)
#y = np.sin(theta)**10
#y = np.sin(theta)**1000
y = np.sin(theta)**77
#y = np.sin(theta)**5
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_top()
ax2.xaxis.tick_bottom()
ax.tick_params(labeltop='off')
ax.plot(x,y,"r")
ax2.plot(x,y,"b")
f.show()
はっきりと区別された2つのグラフに、それぞれ二つ独立させて載せて。。。

ylimを調節して、うまい具合に見えるようにする。
round(max(y))とかで、最大値を丸め込めばいいのではないかと。
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,1,1001)
theta = np.linspace(0,np.pi,1001)
#y = np.sin(theta)
#y = np.sin(theta)**10
y = np.sin(theta)**1000
#y = np.sin(theta)**100
#y = np.sin(theta)**5
f, (ax, ax2) = plt.subplots(2, 1, sharex=True)
ax.spines['bottom'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax.xaxis.tick_top()
ax2.xaxis.tick_bottom()
ax.tick_params(labeltop='off')
ax.plot(x,y,"r")
ax2.plot(x,y,"b")
ax.set_ylim(.7, 1.)
ax2.set_ylim(0, .3)
f.show()

ずばずば。コードは、http://matplotlib.org/examples/pylab_examples/broken_axis.htmlがそのまんま使用できるので、そのまま使用した。だから載せない。
上記コードのplt.show()の前にでも書けばこうなる。

ダメ押し
http://qiita.com/ynakayama/items/8d3b1f7356da5bcbe9bcを参考に、
plt.subplots_adjust(wspace=0, hspace=0.05)
の一行でもってsubplotを縦に詰めてみた。

にょろにょろは。。。
"にょろ"とタイプすると〜が出てくる。〜は「にょろ」だ!見破ったぞ!!ま、こんなの朝飯前さ。自分にかかればこんなことお見通しなんだぜ!!にょろにょろ。すげ
よくみたら、この環境ではsin(θ) [0<θ<2π]になってる。
この記事は、3日前の記事よりも前に書き始めて、中途半端な所で手が止まっていたので、前後してしまった。
内容が重複しているけど、少しでも多くの例を見れたら、面白いかなと思い、やった。
【pythonの最新記事】
- 中速フーリエ変換 ~離散フーリエ変換より..
- 断面二次モーメントを、座標点の配列から計..
- 断面二次モーメントを、座標点の配列から計..
- fontファイルの文字データ(グリフ)を..
- matplotlibのpyplot.pl..
- 計算力学技術者試験の問題集 自炊(裁断→..
- pythonで、ホワイトノイズやピンクノ..
- 脳ドッグに行ってきた。→MRIの画像デー..
- matplotlibのimshowで円を..
- matplotlibの、cmapを、徐々..
- matplotlibのmake_axes..
- matplotlib floatinga..
- matplotlib plotの色を、値..
- Pythonで、「二次元フーリエ変換した..
- matplotlibのlinestyle..
- どちらが正しいRGBか。(matplot..
- matplotlibのannotateの..
- matplotlibで、x軸とy軸の数字..
- VBAで、pythonのrangeとか、..
- matplotlibのaxes3Dで、a..
https://wakelet.com/wake/Y5pep9uVXhsKOyfpi1K_W
https://wakelet.com/wake/CmiFMbzDCibQTQ1Bpmn24
https://wakelet.com/wake/w42A-_og3zuTGBmVLdiK5
https://wakelet.com/wake/0LQM-S1KwogooDIaTy3L4
https://trello.com/c/pAkfk43z/15-usbwibukeydongleemulatorcrack
https://bloodniasemblidar.wixsite.com/unpsychestik/post/activator-stata-12-pc-download-zip-pro
https://trello.com/c/6tOOjJIR/34-free-acrobat-distiller-9-pc-full-utorrent-crack-x64-pro-key
https://retlecimulaperp.wixsite.com/buddnudale/post/watch-online-online-player-pasanga-2-dubbed-english-dvdrip-avi
https://cdn.thingiverse.com/assets/1d/7d/e4/9f/da/Visual-Studio-2018-Enterprise-ISO-Serial-Download-Pc.html
https://socialpirate.org/read-blog/1551
https://melonykorkmas055a1.wixsite.com/compsmalimun/post/ficom-fiat-alfa-lancia-diagnostic-software
https://technospace.co.in/upload/files/2021/10/ZQGjlMnA9R65bqIyEnic_10_56b8b3d8d1830aec5b7e245ad80a3850_file.pdf
https://tritolinunrea.wixsite.com/vieglamtickwa/post/power-geez-2010-software-download
https://downbiztorowalme.wixsite.com/viatifboove/post/wic-reset-v-5-0-2-keygen
https://schelsearchrecaten.wixsite.com/amroworrta/post/visual-studio-2020-crack-license-key-final-free-download
https://roconstegasugma.wixsite.com/krusmenlunchwoodc/post/full-childish-gambi-subtitles-dubbed-avi
https://westkindzingmeesur.wixsite.com/odunniho/post/stronghold-3-1-0-24037-trainer-zip-patch-windows-activation-build
https://trello.com/c/aa6em6lv/23-sound-ineering-explained-by-michael-talbot-smith-download-full-edition-epub-zip-ebook
https://wakelet.com/wake/6kInypunb7ojtZ5lzcO2y
https://herriphichuc.weebly.com/zerene-stacker-104-license-key.html
http://groupobnabit.webblogg.se/2021/november/mad-dog-mccree-remastered-edition-c-digital-leisure-pc-cdrom.html
https://docs.google.com/viewerng/viewer?url=atennis.kz/tour/upload/files/2021/11/6oUUyseWlAZbJEMS2cxp_28_1f7a48650ae1b061083ce3f79bd73b6c_file.pdf
https://www.cloudschool.org/activities/ahFzfmNsb3Vkc2Nob29sLWFwcHI5CxIEVXNlchiAgMDAx_C7CQwLEgZDb3Vyc2UYgIDAwIfZ4ggMCxIIQWN0aXZpdHkYgIDAgNixywkMogEQNTcyODg4NTg4Mjc0ODkyOA
https://uploads.strikinglycdn.com/files/60c34656-050e-44cc-855e-66234b841fd2/Good-Ringtone-Ideas.pdf
https://trello.com/c/M5xldjvd/6-vishwaroop-2-movie-in-hindi-720pl
https://breedalnalarhell.wixsite.com/lighcomraibu/post/x32-rise-full-version-crack-zip
https://urgecivesthand.wixsite.com/plachorosub/post/full-ala-melissa-bonus-key-crack-pc-software
https://rislighpartersheld.wixsite.com/pennsembvergta/post/download-fispoof-hciso-dmg
https://geiclaclysyroki.wixsite.com/duelasraler/post/nck-dongle-full-crack-30
https://sixviocarotee.wixsite.com/dicetingma/post/new-chessbase-mega-database-2012-free-download
https://stephanclark82.wixsite.com/clossisverbno/post/iso-fonepaw-data-recovery-3-1-6-cracked-full-version-64-final-download
https://felixsimpson5.wixsite.com/hoaraciwal/post/descargar-gratis-arcview-3-2-para-windows-7-64-bits
https://www.cloudschool.org/activities/ahFzfmNsb3Vkc2Nob29sLWFwcHI5CxIEVXNlchiAgID_-dSRCAwLEgZDb3Vyc2UYgICA_9Pp-AgMCxIIQWN0aXZpdHkYgIDAkIrMrQoMogEQNTcyODg4NTg4Mjc0ODkyOA
https://www.cloudschool.org/activities/ahFzfmNsb3Vkc2Nob29sLWFwcHI5CxIEVXNlchiAgIC_35_GCgwLEgZDb3Vyc2UYgIDAgL-K0wsMCxIIQWN0aXZpdHkYgIDA4OXh4AoMogEQNTcyODg4NTg4Mjc0ODkyOA
https://www.cloudschool.org/activities/ahFzfmNsb3Vkc2Nob29sLWFwcHI5CxIEVXNlchiAgMCghMH8CAwLEgZDb3Vyc2UYgICAn9uupwgMCxIIQWN0aXZpdHkYgIDAkLH4xQsMogEQNTcyODg4NTg4Mjc0ODkyOA
https://www.cloudschool.org/activities/ahFzfmNsb3Vkc2Nob29sLWFwcHI5CxIEVXNlchiAgID_gPvECwwLEgZDb3Vyc2UYgIDAgISuhAsMCxIIQWN0aXZpdHkYgIDAkLHZogoMogEQNTcyODg4NTg4Mjc0ODkyOA
https://coub.com/stories/2795388-__hot__-average-spring-constant-of-a-rubber-band
https://coub.com/stories/2795387-katyar-kaljat-ghusli-movie-download-300-mb-movies-exclusive
https://coub.com/stories/2795385-gauraiya-full-movies-720p-thorgray
https://coub.com/stories/2795384-free-love-u-family-full-movie-english-download-design-saugen-rider
https://wakelet.com/wake/LELGSANi0hFfFqDcYQ-I0
https://wakelet.com/wake/GfyOfGOi0R5AjLJpqsBxR
https://wakelet.com/wake/A27G7UW_qkEcP4NSaUrat
https://wakelet.com/wake/VIIHDuFpblRipDsLh0OYm
https://wakelet.com/wake/4pyPfHI8WikdOuHy9_6Uc
https://wakelet.com/wake/MDSJp-ll5tnotpuiVJtIh
https://wakelet.com/wake/-qo1tLyRdUgMpaZ-suFeS
https://wakelet.com/wake/UJqPebAejnjxBA9h2Qu_k
https://wakelet.com/wake/aC4ejBOPR-Kx9DcNt9a10
https://wakelet.com/wake/Ns--937PdVKyl0fk-FhDl
https://wakelet.com/wake/eCH58jkz0cWTy8yipHmOQ
https://wakelet.com/wake/uRIM0EfIuJQHRlXJJJb0v
https://wakelet.com/wake/0vPGRrcbaL465SAE7sgWi
https://wakelet.com/wake/-lBGBaOSLfTe6_2QFYbBV
https://wakelet.com/wake/ntlrN4rRehRBq3X3SbTJP
https://wakelet.com/wake/2XwA5cG7q39KDi1y8-Q5z
https://wakelet.com/wake/ydzhuiPAKQ1dVMAPf2z7z
https://wakelet.com/wake/5fkCusxRm3lGPo4z8d401
https://wakelet.com/wake/7-ovOj7MKmBt1oNG3euyw
https://wakelet.com/wake/vNCzICpe9zMyYgMKMmiOp