[英]Seaborn: How to change linewidth and markersize separately in factorplot?
[英]How to change figuresize using seaborn factorplot
%pylab inline
import pandas as pd
import numpy as np
import matplotlib as mpl
import seaborn as sns
typessns = pd.DataFrame.from_csv('C:/data/testesns.csv', index_col=False, sep=';')
mpl.rc("figure", figsize=(45, 10))
sns.factorplot("MONTH", "VALUE", hue="REGION", data=typessns, kind="box", palette="OrRd");
我總是得到一個小尺寸的數字,無論我在 figsize 中指定了什么尺寸......如何解決它?
2019 年添加的注釋:在現代 seaborn 版本中,
size
參數已重命名為height
。
更具體一點:
%matplotlib inline
import seaborn as sns
exercise = sns.load_dataset("exercise")
# Defaults are size=5, aspect=1
sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=2, aspect=1)
sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=4, aspect=1)
sns.factorplot("kind", "pulse", "diet", exercise, kind="point", size=4, aspect=2)
在構建繪圖時,您希望將參數“size”或“aspect”傳遞給 sns.factorplot()。
尺寸會改變高度,同時保持縱橫比(所以如果只改變尺寸,它也會變寬。)
Aspect將改變寬度,同時保持高度不變。
上面的代碼應該可以在 ipython notebook 本地運行。
在這些示例中縮小了繪圖大小以顯示效果,並且因為上述代碼中的繪圖在保存為 png 時相當大。 這也表明 size/aspect 包括邊距中的圖例。
大小=2,方面=1
大小=4,方面=1
大小=4,方面=2
此外,一旦加載“sns”模塊,就可以查看此繪圖函數的所有其他有用參數/參數和默認值:
help(sns.factorplot)
mpl.rc
存儲在全局字典中(參見http://matplotlib.org/users/customizing.html )。 所以,如果你只想改變一個數字的大小(本地),它會做到這一點:
plt.figure(figsize=(45,10))
sns.factorplot(...)
它使用matplotlib-1.4.3
和seaborn-0.5.1
對我seaborn-0.5.1
圖形的size
由factorplot
的size
和aspect
參數factorplot
。 它們對應於每個面的大小(“ size
”實際上表示“高度”,然后size * aspect
給出寬度),因此如果您的目標是整個圖形的特定大小,則需要從那里向后工作。
import seaborn as sns
sns.set(rc={'figure.figsize':(12.7,8.6)})
plt.figure(figsize=(45,10))
%pylab inline
,它已被棄用,使用%matplotlib inline
.set_style
函數,將你的 rc 作為第二個參數或 kwarg 傳遞給它。: http ://web.stanford.edu/~mwaskom/software/seaborn/generated/seaborn.set_style.html如果您只想縮放圖形,請使用以下代碼:
import matplotlib.pyplot as plt
plt.figure(figsize=(8, 6))
sns.factorplot("MONTH", "VALUE", hue="REGION", data=typessns, kind="box", palette="OrRd"); // OR any plot code
截至 2018 年 7 月的注意事項:
seaborn.__version__ == 0.9.0
影響上述答案的兩個主要變化
factorplot
函數已重命名為catplot()
對於多圖網格函數和使用它們的函數, size
參數已重命名為height
。
這意味着@Fernando Hernandez提供的答案應按以下方式進行調整:
%matplotlib inline
import seaborn as sns
exercise = sns.load_dataset("exercise")
# Defaults are hieght=5, aspect=1
sns.catplot("kind", "pulse", "diet", exercise, kind="point", height=4, aspect=2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.