[英]Creating a definition to overlay or more plt.plot() using definitions in Python
For the life of me I can't figure this out, and I've been at it for a few hours now.对于我的一生,我无法弄清楚这一点,而且我已经做了几个小时了。 I would like to create a chart, that I can overlay multiple charts on.我想创建一个图表,我可以在上面叠加多个图表。 I've created a definition for the chart, but it doesn't return anything (I've tried to modify it to return an ax, but that doesn't work either).我已经为图表创建了一个定义,但它没有返回任何东西(我试图修改它以返回斧头,但这也不起作用)。 As it stands it outputs two seperate charts, perfectly the way I want it to work.就目前而言,它输出两个单独的图表,完全符合我希望它的工作方式。 However, I'd like it to print 1 chart, with both lines overprinted.但是,我希望它打印 1 个图表,两条线都被叠印。 Here is where my code is at:这是我的代码所在的位置:
def plot_tera_wasserburg_concordia(lambda238=1.54*10**-10,
lambda235=9.72*10**-10,
show_ages=True,
title="Tera-Wasserburg Concordia Diagram",
linecolor="r"):
df = get_ratio_data(lambda238, lambda235) # I've defined this elsewhere
fig = plt.figure(figsize=(12,16))
ax = fig.add_subplot()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.set_xlim([0,35])
ax.set_ylim([0,0.62])
plt.xlabel("238U/206Pb", fontsize=16)
plt.ylabel("207Pb/206Pb", fontsize=16)
plt.title(title, fontsize=22)
if show_ages == True:
get_ages(lambda238, lambda235, 'tw') # I've defined this elsewhere
plt.plot(df["ratio_238U_206Pb"], df["ratio_207Pb_206Pb"], linecolor, zorder=1)
geochron.plot_tera_wasserburg_concordia(show_ages=False)
lambda238=1.55125*10**-10
lambda235=9.8485*10**-10
geochron.plot_tera_wasserburg_concordia(lambda238,
lambda235,
show_ages=False,
linecolor="g")
plt.show()
The problem is that you create the figure inside the function.问题是您在 function 中创建了图形。 So you create a new figure every time you call plot_tera_wasserburg_concordia
.因此,每次调用plot_tera_wasserburg_concordia
时都会创建一个新图形。 I suggest you move the common creation/ labels outside the function.我建议您将公共创建/标签移到 function 之外。 That's from the fig = plt.figure(figsize=(12,16))
line until the plt.title(title, fontsize=22)
line.这是从fig = plt.figure(figsize=(12,16))
行到plt.title(title, fontsize=22)
行。 Then call the function twice, followed by plt.show()
然后调用 function 两次,然后调用plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.