![](/img/trans.png)
[英]Align x-axis ticks in shared subplots of heatmap and line plots using Seaborn and Matplotlib
[英]Change number of x-axis ticks in seaborn plots
我希望能够在Python 3.5中控制seaborn图上的轴刻度数。 我已经习惯使用R的ggplot了,所以我在Python中使用类似的功能时遇到了一些麻烦。
举个例子,这是我目前正在使用的数据类型:
test = pd.DataFrame()
test["X"] = [1,2,3,1,2,3]
test["Y"] = [1,5,3,7,2,4]
test["Category"] = ["A", "A", "A", "B", "B", "B"]
我想通过这样做来做像ggplot的facet_wrap()这样的事情:
sns.set(style = "ticks", color_codes = True)
test_plot = sns.FacetGrid(test, col = "Category")
test_plot = (test_plot.map(sns.plt.plot, "X", "Y").add_legend())
test_plot.set_xticks(np.arange(1,4,1))
sns.plt.show(test_plot)
但是,我收到以下错误。 问题似乎是关于在FacetGrid中设置轴标签,但我不知道如何解决它。 这是Python 3的问题还是在刻面图上指定轴?
UserWarning: tight_layout : falling back to Agg renderer
warnings.warn(“tight_layout:回退到Agg渲染器”)
test_plot.set_xticks(np.arange(1,4,1))
AttributeError: 'FacetGrid' object has no attribute 'set_xticks'
set_xticks
是matplotlib Axes对象上的一个方法,但FacetGrid
有很多轴。 你可以遍历它们并在每个上面设置xticks,但更简单的方法是调用FacetGrid.set(xticks=np.arange(1,4,1))
,它将在内部进行循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.