Python 如何标记和更改 Seaborn kdeplot 轴的比例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30819056/
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
How to label and change the scale of Seaborn kdeplot's axes
提问by iatowks
Here's my code
这是我的代码
import numpy as np
from numpy.random import randn
import pandas as pd
from scipy import stats
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
fig = sns.kdeplot(treze, shade=True, color=c1,cut =0, clip=(0,2000))
fig = sns.kdeplot(cjjardim, shade=True, color=c2,cut =0, clip=(0,2000))
fig.figure.suptitle("Plot", fontsize = 24)
plt.xlabel('Purchase amount', fontsize=18)
plt.ylabel('Distribution', fontsize=16)
, which results in the following plot:
,结果如下图:
I want to do two things:
我想做两件事:
1) Change the scale of the y-axis by multiplying its values by 10000 and, if it's possible, add a % sign to the numbers. In other words, I want the y-axis values shown in the above plot to be 0%, 5%, 10%, 15%, 20%, 25%, and 30%.
1) 通过将 y 轴的值乘以 10000 来更改 y 轴的比例,如果可能,在数字上添加一个 % 符号。换句话说,我希望上图中显示的 y 轴值为 0%、5%、10%、15%、20%、25% 和 30%。
2) Add more values to the x-axis. I'm particularly interested in showing the data in intervals of 200. In other words, I want the x-axis values shown in the plot to be 0, 200, 400, 600,... and so on.
2) 向 x 轴添加更多值。我对以 200 为间隔显示数据特别感兴趣。换句话说,我希望图中显示的 x 轴值为 0、200、400、600...等等。
采纳答案by cattt84
1) what you are looking for is most probably some combination of get_yticks() and set_yticks:
1)您正在寻找的很可能是 get_yticks() 和 set_yticks 的某种组合:
plt.yticks(fig.get_yticks(), fig.get_yticks() * 100)
plt.ylabel('Distribution [%]', fontsize=16)
Note: as mwaskom is commenting times 10000 and a % sign is mathematically incorrect.
注意:因为 mwaskom 正在评论 10000 次,% 符号在数学上是不正确的。
2) you can specify where you want your ticks via the xticks function. Then you have more ticks and data get easier to read. You do not get more data that way.
2) 您可以通过 xticks 函数指定您想要的位置。然后你有更多的滴答声,数据变得更容易阅读。您不会以这种方式获得更多数据。
plt.xticks([0, 200, 400, 600])
plt.xlabel('Purchase amount', fontsize=18)
Note: if you wanted to limit the view to your specified x-values you might even have a glimpse at plt.xlim() and reduce the figure to the interesting range.
注意:如果您想将视图限制为您指定的 x 值,您甚至可以瞥见 plt.xlim() 并将数字缩小到有趣的范围。