Mpld3: λ²”λ‘€ λ§ˆμ»€κ°€ μ‚°μ λ„μ—μ„œ λ Œλ”λ§λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

에 λ§Œλ“  2015λ…„ 05μ›” 15일  Β·  4μ½”λ©˜νŠΈ  Β·  좜처: mpld3/mpld3

산점도에 # 185와 μœ μ‚¬ν•œ λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆλ‹€. κ·ΈλŸ¬λ‚˜ framealpha 해킹은 μ—¬κΈ°μ„œ νš¨κ³Όμ μ΄μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

import numpy as np
import matplotlib.pyplot as plt
import mpld3

%matplotlib inline

mpld3.enable_notebook()

fig, ax = plt.subplots()
ax.scatter(np.random.randn(10), np.random.randn(10), color="red", label="data1")
ax.scatter(np.random.randn(10), np.random.randn(10), color="blue", label="data2")
ax.legend(title="Cluster", loc="best", framealpha=0)

svgμ—λŠ” λ§ˆμ»€μ— λŒ€ν•œ g μš”μ†Œκ°€ μžˆμ§€λ§Œ 범둀에 λ Œλ”λ§λ˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. λ‚΄ μ½”λ“œμ— λ¬Έμ œκ°€ μžˆμŠ΅λ‹ˆκΉŒ?

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

또 λ‹€λ₯Έ 직접적인 ν•΄κ²° 방법은 μ‚°μ λ„μ—μ„œ λ ˆμ΄λΈ”μ„ μ œκ±°ν•œ λ‹€μŒ ax.plot() 둜 빈 배열을 ν”Œλ‘œνŒ…ν•˜μ—¬ λ²”λ‘€λ₯Ό μ±„μš°λŠ” κ²ƒμž…λ‹ˆλ‹€. κ·Έλž˜μ„œ λŒ€μ‹ 

fig, ax = plt.subplots()
ax.scatter(np.random.randn(10), np.random.randn(10), color="red", label="data1")
ax.scatter(np.random.randn(10), np.random.randn(10), color="blue", label="data2")
ax.legend(title="Cluster", loc="best", framealpha=0)

λ„Œ ν•  μˆ˜μžˆμ–΄

fig, ax = plt.subplots()
ax.scatter(np.random.randn(10), np.random.randn(10), color="red")
ax.plot([], [], "o", color="red", label="data1")
ax.scatter(np.random.randn(10), np.random.randn(10), color="blue")
ax.plot([], [], "o", color="blue", label="data2")
ax.legend(title="Cluster", loc="best", framealpha=0)

λ²”λ‘€μ—λŠ” 컬러 λ§ˆμ»€κ°€ ν¬ν•¨λ©λ‹ˆλ‹€.

λͺ¨λ“  4 λŒ“κΈ€

λ²„κ·Έμ²˜λŸΌ λ³΄μž…λ‹ˆλ‹€. μˆ˜μ • 사항이 있으면 κΈ°λΆ€λ₯Ό ν™˜μ˜ν•©λ‹ˆλ‹€!

이 λ¬Έμ œκ°€ μ „ν˜€ ν•΄κ²°λ˜μ§€ μ•Šμ•˜λŠ”μ§€ λͺ¨λ₯΄κ² μ§€λ§Œ, λ‹€λ₯Έ μ‚¬λžŒμ΄ ν•΄κ²° 방법이 ν•„μš”ν•˜κ³  λ²”λ‘€μ˜ νŠΉμ • λ ˆμ΄λΈ”μ— λŒ€ν•œ 색상 만 ν‘œμ‹œν•˜λŠ” λ°μ—λ§Œ κ΄€μ‹¬μ΄μžˆλŠ” 경우 (적어도 κ°€μΉ˜κ°€μžˆλŠ”) 글꼴을 μ„€μ •ν–ˆμŠ΅λ‹ˆλ‹€. 색상

    l = ax.legend(fancybox=0)
    for i, text in enumerate(l.get_texts()):
        text.set_color(colors[i])

또 λ‹€λ₯Έ 직접적인 ν•΄κ²° 방법은 μ‚°μ λ„μ—μ„œ λ ˆμ΄λΈ”μ„ μ œκ±°ν•œ λ‹€μŒ ax.plot() 둜 빈 배열을 ν”Œλ‘œνŒ…ν•˜μ—¬ λ²”λ‘€λ₯Ό μ±„μš°λŠ” κ²ƒμž…λ‹ˆλ‹€. κ·Έλž˜μ„œ λŒ€μ‹ 

fig, ax = plt.subplots()
ax.scatter(np.random.randn(10), np.random.randn(10), color="red", label="data1")
ax.scatter(np.random.randn(10), np.random.randn(10), color="blue", label="data2")
ax.legend(title="Cluster", loc="best", framealpha=0)

λ„Œ ν•  μˆ˜μžˆμ–΄

fig, ax = plt.subplots()
ax.scatter(np.random.randn(10), np.random.randn(10), color="red")
ax.plot([], [], "o", color="red", label="data1")
ax.scatter(np.random.randn(10), np.random.randn(10), color="blue")
ax.plot([], [], "o", color="blue", label="data2")
ax.legend(title="Cluster", loc="best", framealpha=0)

λ²”λ‘€μ—λŠ” 컬러 λ§ˆμ»€κ°€ ν¬ν•¨λ©λ‹ˆλ‹€.

https://github.com/mpld3/mplexporter/pull/54 가이 문제λ₯Ό ν•΄κ²°ν•΄μ•Όν•©λ‹ˆλ‹€!

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰