[英]matplotlib scatterplot x axis labels
當我將 c 選項添加到 matplotlib 中的散點圖時,x 軸標簽消失。 這是一個例子: https : //github.com/Kornel/scatterplot-matplotlib/blob/master/Scatter%20plot%20x%20axis%20labels.ipynb (歡迎拉請求:))
這是與筆記本中相同的示例:
import pandas as pd
import matplotlib.pyplot as plt
test_df = pd.DataFrame({
"X": [1, 2, 3, 4],
"Y": [5, 4, 2, 1],
"C": [1, 2, 3, 4]
})
現在比較結果:
test_df.plot(kind="scatter", x="X", y="Y", s=50);
到:
test_df.plot(kind="scatter", x="X", y="Y", c="C");
x 軸標簽在哪里? 這是我缺少的功能嗎?
熊貓版本:0.18.1 Matplotlib:1.5.3 Python:3.5.2
感謝您的幫助,科內爾
編輯:@Kewl 指出的解決方案是調用 plt.subplots 並指定軸:
fig, ax = plt.subplots()
test_df.plot(kind="scatter", x="X", y="Y", s=50, c="C", cmap="plasma", ax=ax);
給
PS 看起來像是 jupyter 問題,在沒有 jupyter notebook 的情況下調用時標簽很好
你可以這樣做。
plt.scatter(x="X", y="Y", c=df.color)
plt.xlabel("X axis label")
plt.ylabel("Y axis label")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.