我目前正在尝试使用Seaborn为我的学术论文创建情节.这些图看起来很棒且易于生成,但是我遇到的一个问题是对图中的字体大小进行了精细控制.
我的论文中的字体大小为9pt,我想确保我的图中的字体大小为9pt或10pt.但在seaborn中,字体大小主要通过字体缩放来控制sns.set_context("paper", font_scale=0.9)
.所以除了通过反复试验之外,我很难找到合适的字体大小.有没有更有效的方法来做到这一点?
我还想确保不同的seaborn图之间的字体大小是一致的.但并非所有的seaborn图都具有相同的尺寸,所以看起来在所有图上使用相同的font_scale并不一定会在这些不同的图上创建相同的字体大小?
我在下面附上了我的代码.我很感激有关如何为两栏学术论文格式化图表的任何评论.我的目标是能够控制图形的大小而不会扭曲字体大小或图形.我用Latex写论文.
# Seaborn setting
sns.set(style='whitegrid', rc={"grid.linewidth": 0.1})
sns.set_context("paper", font_scale=0.9)
plt.figure(figsize=(3.1, 3)) # Two column paper. Each column is about 3.15 inch wide.
color = sns.color_palette("Set2", 6)
# Create a box plot for my data
splot = sns.boxplot(data=df, palette=color, whis=np.inf,
width=0.5, linewidth = 0.7)
# Labels and clean up on the plot
splot.set_ylabel('Normalized WS')
plt.xticks(rotation=90)
plt.tight_layout()
splot.yaxis.grid(True, clip_on=False)
sns.despine(left=True, bottom=True)
plt.savefig('test.pdf', bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud) 我明白同时scale
改变两个参数,但我希望达到在大标记之间连接细线的效果.
我也尝试过调整大小rc{'lines.linewidth' = 1, 'lines.markersize' = 5}
,但它最终会同时缩放标记大小和线宽,而不是单独设置它们.基本上,markersize
由于某种原因没有效果.
编辑:添加绘图和代码以显示问题
import seaborn as sns
sns.set(style="whitegrid")
paper_rc = {'lines.linewidth': 1, 'lines.markersize': 10}
sns.set_context("paper", rc = paper_rc)
# Load the example exercise dataset
df = sns.load_dataset("exercise")
# Draw a pointplot to show pulse as a function of three categorical factors
g = sns.factorplot(x="time", y="pulse", hue="kind", col="diet", data=df,
palette="YlGnBu_d", size=6, aspect=.75)
g.despine(left=True)
Run Code Online (Sandbox Code Playgroud)
下面的前两个数字分别使用标记1和10创建.如图所示,它们似乎具有相同的标记.最后一个数字使用line.linewidth=10 line.markersize=1
,它扩大了线宽和标记.
我想知道是否有一种好方法可以将颜色条的标签垂直向下移动一些偏移量?
我试过bar.ax.yaxis.labelpad,它允许我将标签水平移动一些偏移量,但不能垂直移动。
我知道bar.ax.yaxis.set_label_coords(x,y),它可以显式设置坐标。但问题是我不知道如何获取初始坐标值来为我设置y坐标的相对偏移。