LoginSignup
0
1

More than 3 years have passed since last update.

枠など全て消して、背景が透明なグラフを作成

Posted at

枠など全て消して、背景が透明なグラフを作成

PowerPointとかで、グラフを張り付けるとき枠とか軸が要らない時、
色々表示しないように設定が必要。忘れそうなのでメモ。

波形をグラフ化して、PNGファイルで保存する。
透明部分が結構広いのが玉の傷。個々も削れるのだろうか。

import soundfile as sf
import matplotlib.pyplot as plt

# 波形読み込み
a1,fs=sf.read("a1.wav")
b1,fs=sf.read("b1.wav")
c1,fs=sf.read("c1.wav")
n1,fs=sf.read("n1.wav")

settings = [
    """
    (a1, "g_a1.png", "#808080"),
    (b1, "g_b1.png", "#4d4d4d"),
    (c1, "g_c1.png", "#b2b2b2"),
    (n1, "g_n1.png", "#dddddd"),
    """

    (a1, "c_a1.png", "#FBBF9C"),
    (b1, "c_b1.png", "#ff9999"),
    (c1, "c_c1.png", "#B8B400"),
    (n1, "c_n1.png", "darkgrey"),
]

for value, name, color in settings:
    fig, ax = plt.subplots()
    fig.patch.set_alpha(0)
    ax.patch.set_alpha(0)
    ax.plot(value, c=color)
    plt.ylim(-0.8, 0.8)
    plt.tick_params(labelbottom=False, labelleft=False, labelright=False, labeltop=False, bottom=False, left=False, right=False, top=False)
    plt.gca().spines['right'].set_visible(False)
    plt.gca().spines['top'].set_visible(False)
    plt.gca().spines['left'].set_visible(False)
    plt.gca().spines['bottom'].set_visible(False)
    fig.savefig(name, transparent=True)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1