Matplotlib は、科学技術コンピューティングにおけるデータ視覚化のための Python ツールボックスです。これを使用すると、Python で Matlab や Octave などのさまざまなデータ グラフィックを描画できます。以下の記事ではPythonでmatplotlibを使って折れ線グラフを描く方法を中心に紹介していますので、困っている方は参考にしてみてください。
matplotlib の紹介
matplotlib は、Python で最も有名な描画ライブラリであり、対話型描画に非常に適した matlab に似た一連のコマンド API を提供します。また、描画コントロールとして簡単に使用したり、GUI アプリケーションに埋め込んだりすることもできます。
そのドキュメントは非常に完全で、ギャラリーページには何百ものサムネイルがあり、開くとソースプログラムが利用可能になります。したがって、特定の種類の図を描画する必要がある場合は、このページを参照/コピー/ペーストするだけで基本的に作業は完了します。
Linux で最も有名なデータ グラフ ツールは gnuplot です。これは無料です。Python には gnuplot を呼び出すことができるパッケージがありますが、構文は馴染みがなく、描画品質は高くありません。
Matplotlib は比較的強力です: Matlab の構文、Python 言語、Latex の描画品質 (組み込みの Latex エンジンによって描画された数式も使用できます)。
描画ライブラリ Matplotlib のインストール方法: ここをクリック
matplotlib は折れ線グラフを描画します
1. 2. 伝説
プロット内 ラベルを指定する場合、凡例メソッドを呼び出して凡例を描画します。例:import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi, 100) y1, y2 = np.sin(x), np.cos(x) plt.plot(x, y1) plt.plot(x, y2) plt.title('line chart') plt.xlabel('x') plt.ylabel('y') plt.show()

legend メソッドは、凡例の位置を設定する loc キーワード パラメータを受け入れます。 可能な値は数値または文字列です:
0: 'best'
1 : 「右上」
2: 「左上」
(1) 色
1、色の名前または略語
b: ブルー
g: グリーン
r: レッド
c: シアン
線のスタイルを設定するには、plotメソッドのキーワードパラメータlinestyle(またはls)を使用します。可能な値は次のとおりです:
--、破線
- :、点線
- ''、' '、なし
- (3) 太さ プロットメソッドのキーワードパラメータ linewidth (または lw) を設定することで線の太さを変更でき、その値は浮動小数点数です。
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi, 100) y1, y2 = np.sin(x), np.cos(x) plt.plot(x, y1, label='y = sin(x)') plt.plot(x, y2, label='y = cos(x)') plt.legend() plt.show()
4. マーカー
次のキーワードパラメータを使用してマーカースタイルを設定できます: markerマーカーエッジ幅またはミュウ
- マーカーフェイスカラーまたはmfc
- マーカーフェイスカラーオルトまたはmfcalt
- マーカーサイズまたはms
- 、マーカーの可能な値は次のとおりです:
- ': ポイントマーカー
- 」 ,': ピクセルマーカー
- 'v': 三角下マーカー
- '^': 三角上マーカー
- '
'>': triangle_right marker
'1': tri_down marker
'2': tri_up marker
'3': tri_left marker
'4': tri_right marker
's': square marker
'p': pentagon marker
'*': star marker
'h': hexagon1 marker
'H': hexagon2 marker
'+': plus marker
'x': x marker
'D': diamond marker
'd': thin_diamond marker
'|': vline marker
'_': hline marker
例如:
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi, 10) y1, y2 = np.sin(x), np.cos(x) plt.plot(x, y1, marker='o', mec='r', mfc='w') plt.plot(x, y2, marker='*', ms=10) plt.show()
另外,marker关键字参数可以和color以及linestyle这两个关键字参数合并为一个字符串。例如:
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi, 10) y1, y2 = np.sin(x), np.cos(x) plt.plot(x, y1, 'ro-') plt.plot(x, y2, 'g*:', ms=10) plt.show()
更多matplotlibを使用して折れ線グラフを描画するためのPythonチュートリアル相关文章请关注PHP中文网!

Pythonlistscanstoreanydatatype,arraymodulearraysstoreonetype,andNumPyarraysarefornumericalcomputations.1)Listsareversatilebutlessmemory-efficient.2)Arraymodulearraysarememory-efficientforhomogeneousdata.3)NumPyarraysareoptimizedforperformanceinscient

heouttemptemptostoreavure ofthewrongdatatypeinapythonarray、yure counteractypeerror.thisduetothearraymodule'sstricttypeeencultionyを使用します

PythonListSarePartOfThestAndardarenot.liestareBuilting-in、versatile、forStoringCollectionsのpythonlistarepart。

theScriptisrunningwithwrongthonversionduetorectRectDefaultEntertersettings.tofixthis:1)CheckthedededefaultHaulthonsionsingpython - versionorpython3-- version.2)usevirtualenvironmentsbycreatingonewiththon3.9-mvenvmyenv、andverixe

PythonArraysSupportVariousoperations:1)SlicingExtractsSubsets、2)Appending/ExtendingAdddesements、3)inSertingSelementSatspecificpositions、4)remvingingDeletesements、5)sorting/verversingsorder、and6)listenionsionsionsionsionscreatenewlistsebasedexistin

numpyarraysAressertialentionsionceivationsefirication-efficientnumericalcomputations andDatamanipulation.theyarecrucialindatascience、mashineelearning、物理学、エンジニアリング、および促進可能性への適用性、scaledatiencyを効率的に、forexample、infinancialanalyyy

UseanArray.ArrayOverAlistinPythonは、Performance-criticalCode.1)homogeneousdata:araysavememorywithpedelements.2)Performance-criticalcode:Araysofterbetterbetterfornumerumerumericaleperations.3)interf

いいえ、notallistoperationSaresuptedbyarrays、andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorintorintorinsertizizing、whosimpactsporformance.2)リスト


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

ドリームウィーバー CS6
ビジュアル Web 開発ツール

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

Dreamweaver Mac版
ビジュアル Web 開発ツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

ホットトピック









