pandas matplotlib 散点图 x 轴标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43121584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
matplotlib scatterplot x axis labels
提问by Kornel
When I'm adding the c option to a scatterplot in matplotlib, the x axis labels dissapear. Here's an example: https://github.com/Kornel/scatterplot-matplotlib/blob/master/Scatter%20plot%20x%20axis%20labels.ipynb(pull requests are welcome:))
当我将 c 选项添加到 matplotlib 中的散点图时,x 轴标签消失。这是一个例子:https: //github.com/Kornel/scatterplot-matplotlib/blob/master/Scatter%20plot%20x%20axis%20labels.ipynb(欢迎拉取请求:))
Here's the same example as in the notebook:
这是与笔记本中相同的示例:
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]
})
Now compare the result of:
现在比较结果:
test_df.plot(kind="scatter", x="X", y="Y", s=50);
To:
到:
test_df.plot(kind="scatter", x="X", y="Y", c="C");
Where are the x axis labels? Is this a feature I'm missing?
x 轴标签在哪里?这是我缺少的功能吗?
Pandas version: 0.18.1 Matplotlib: 1.5.3 Python: 3.5.2
Pandas版本:0.18.1 Matplotlib:1.5.3 Python:3.5.2
Thanks for any help, Kornel
感谢您的帮助,科内尔
EDIT: The solutionas pointed out by @Kewl is to call plt.subplots and specify the axes:
编辑:@Kewl 指出的解决方案是调用 plt.subplots 并指定轴:
fig, ax = plt.subplots()
test_df.plot(kind="scatter", x="X", y="Y", s=50, c="C", cmap="plasma", ax=ax);
gives
给
P.S. It looks like a jupyter issue, the label is fine when called without a jupyter notebook
PS 看起来像是 jupyter 问题,在没有 jupyter notebook 的情况下调用时标签很好