Python-data-science-python-chart-properties

提供:Dev Guides
移動先:案内検索

Python-チャートプロパティ

Pythonには、データの視覚化のための優れたライブラリがあります。 Pandasnumpy 、および matplotlib の組み合わせは、ほぼすべての種類の視覚化チャートの作成に役立ちます。 この章では、いくつかの簡単なチャートとチャートのさまざまなプロパティを見ていきます。

チャートを作成する

numpyライブラリを使用して、チャートを作成するためにマッピングする必要な数値を作成し、matplotlibでpyplotメソッドを使用して実際のチャートを描画します。

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,10)
y = x ^ 2
#Simple Plot
plt.plot(x,y)

その*出力*は次のとおりです-

chartprop1.png

軸のラベリング

以下に示すように、ライブラリの適切なメソッドを使用して、チャートのタイトルだけでなく軸にもラベルを適用できます。

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,10)
y = x ^ 2
#Labeling the Axes and Title
plt.title("Graph Drawing")
plt.xlabel("Time")
plt.ylabel("Distance")
#Simple Plot
plt.plot(x,y)

その*出力*は次のとおりです-

chartprop2.png

線種と色のフォーマット

以下に示すように、ライブラリの適切なメソッドを使用して、チャートの線のスタイルと色を指定できます。

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,10)
y = x ^ 2
#Labeling the Axes and Title
plt.title("Graph Drawing")
plt.xlabel("Time")
plt.ylabel("Distance")

# Formatting the line colors
plt.plot(x,y,'r')

# Formatting the line type
plt.plot(x,y,'>')

その*出力*は次のとおりです-

chartprop3.png

チャートファイルの保存

以下に示すように、ライブラリの適切なメソッドを使用して、チャートをさまざまな画像ファイル形式で保存できます。

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0,10)
y = x ^ 2
#Labeling the Axes and Title
plt.title("Graph Drawing")
plt.xlabel("Time")
plt.ylabel("Distance")

# Formatting the line colors
plt.plot(x,y,'r')

# Formatting the line type
plt.plot(x,y,'>')

# save in pdf formats
plt.savefig('timevsdist.pdf', format='pdf')

上記のコードは、Python環境のデフォルトパスにPDFファイルを作成します。