You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

技术问询:如何在同一张图中绘制两个指定正态分布的密度曲线

Plotting Two Normal Distribution Density Curves on the Same Figure: Operational Check

Hey there! Since you're just looking to confirm the steps for plotting these two normal distributions (and not asking for the final answer), let's break down the key operations you need to follow—no worries if you're still getting the hang of this, we'll keep it straightforward:

  • First, set up your x-axis range
    You need a set of x-values that covers the bulk of both distributions. For N(µ=1, σ²=1), most data falls between -2 and 4; for N(µ=-3.5, σ²=3/4) (σ ≈ 0.866), most data is between -5.23 and -1.77. A range like -6 to 5 with 1000 evenly spaced points will work perfectly for smooth curves.

  • Calculate the density values for each distribution

    • For N(µ=1, σ²=1): Compute the probability density function (PDF) at every x-value. If using Python, that's scipy.stats.norm.pdf(x, loc=1, scale=1); in R, it's dnorm(x, mean=1, sd=1).
    • For N(µ=-3.5, σ²=3/4): Remember σ is the square root of variance, so use sqrt(3/4) as the standard deviation. In Python, that's scipy.stats.norm.pdf(x, loc=-3.5, scale=np.sqrt(3/4)); in R, dnorm(x, mean=-3.5, sd=sqrt(3/4)).
  • Plot both curves on the same axes

    • Python (Matplotlib): Initialize your plot, then call plt.plot() for each PDF, add labels to distinguish them, and include a legend. Example snippet structure:
      import numpy as np
      import scipy.stats as stats
      import matplotlib.pyplot as plt
      
      x = np.linspace(-6, 5, 1000)
      pdf1 = stats.norm.pdf(x, loc=1, scale=1)
      pdf2 = stats.norm.pdf(x, loc=-3.5, scale=np.sqrt(3/4))
      
      plt.plot(x, pdf1, label="N(µ=1, σ²=1)")
      plt.plot(x, pdf2, label="N(µ=-3.5, σ²=3/4)")
      plt.legend()
      plt.xlabel("X")
      plt.ylabel("Density")
      plt.show()
      
    • R: Start with a base plot for the first curve, then use lines() to add the second. Example structure:
      x <- seq(-6, 5, length.out = 1000)
      pdf1 <- dnorm(x, mean = 1, sd = 1)
      pdf2 <- dnorm(x, mean = -3.5, sd = sqrt(3/4))
      
      plot(x, pdf1, type = "l", col = "blue", xlab = "X", ylab = "Density")
      lines(x, pdf2, col = "red")
      legend("topright", legend = c("N(µ=1, σ²=1)", "N(µ=-3.5, σ²=3/4)"), col = c("blue", "red"), lty = 1)
      

Does this match the approach you were thinking of? If you have any specific step you're unsure about, feel free to clarify!

内容的提问来源于stack exchange,提问作者abc123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:12:20