pandas 设置 seaborn 关节图的轴刻度值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34209140/
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
Setting the axes tick values of a seaborn jointplot
提问by Okechukwu Ossai
I'm trying to make the x and y axes (including axes tick values) of my jointplot to start and end with specific values and to be scaled in set increments.
我试图让我的关节图的 x 和 y 轴(包括轴刻度值)以特定值开始和结束,并以设定的增量进行缩放。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
g = sns.jointplot(x="LONGITUDE", y="LATITUDE", data=data,
kind='reg', color="#774499", dropna=True, size=7, space=0.3, ratio=5,
xlim=(-180,180), ylim=(-90,90), fit_reg=False);
plt.rc("legend", fontsize=15)
plt.xlabel('Longitude', fontsize=15)
plt.ylabel('Latitude', fontsize=15)
plt.title('Spatial Location Plot', fontsize=15 )
plt.tick_params(axis="both", labelsize=15)
Notice that the lower and upper edges of both axes do not have any tick values. I want the tick values to start and end at the axes edges using exactly the values I specified in xlim() and ylim().
请注意,两个轴的下边缘和上边缘都没有任何刻度值。我希望刻度值使用我在 xlim() 和 ylim() 中指定的值在轴边缘开始和结束。
My preferred increments are 90 and 45 degrees for the X and Y axes respectively. So, I want the X axis to look this: -180, -90, 0, 90, 180. And the Y axis to be: -90, -45, 0, 45, 90. Thanks for your suggestions.
我的首选增量分别是 X 和 Y 轴的 90 度和 45 度。所以,我希望 X 轴看起来像这样:-180、-90、0、90、180。Y 轴是:-90、-45、0、45、90。感谢您的建议。
采纳答案by tmdavison
You can use matplotlib.ticker
to set the major_locator
on the axes. The JointGrid
returned by jointplot
(g
) has a ax_joint
attribute, which we can use to set the ticks. To set ticks every multiple of a number, we can use a MultipleLocator
:
您可以使用matplotlib.ticker
来设置major_locator
轴上的 。将JointGrid
通过返回jointplot
(g
)有一个ax_joint
属性,我们可以用它来设置刻度。要设置数字的每个倍数的刻度,我们可以使用MultipleLocator
:
import matplotlib.ticker as ticker
g.ax_joint.xaxis.set_major_locator(ticker.MultipleLocator(90))
g.ax_joint.yaxis.set_major_locator(ticker.MultipleLocator(45))