zoukankan      html  css  js  c++  java
  • Matplotlib Superscript format in matplotlib plot legend 上标下标

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots()
    ax.set(title=r'This is an expression $e^{sin(omegaphi)}$',
           xlabel='meters $10^1$', ylabel=r'Hertz $(frac{1}{s})$')
    plt.show()

    import matplotlib.pyplot as plt
    import numpy as np
    from scipy.optimize import curve_fit

    x_data = np.linspace(0.05,1,101)
    y_data = 1/x_data
    noise = np.random.normal(0, 1, y_data.shape)
    y_data2 = y_data + noise

    def func_power(x, a, b):
        return a*x**b

    popt, pcov= curve_fit(func_power, x_data, y_data2)

    plt.figure()
    plt.scatter(x_data, y_data2, label = 'data')
    plt.plot(x_data, popt[0] * x_data ** popt[1], label = ("$y = {{{}}}x^{{{}}}$").format(round(popt[0],2), round(popt[1],2)))
    plt.plot(x_data, x_data**3, label = '$x^3$')
    plt.legend()
    plt.show()

    import matplotlib.pyplot as plt
    import numpy as np
    from scipy.optimize import curve_fit
    
    x_data = np.linspace(0.05,1,101)
    y_data = 1/x_data
    noise = np.random.normal(0, 1, y_data.shape)
    y_data2 = y_data + noise
    
    def func_power(x, a, b):
        return a*x**b 
    
    popt, pcov= curve_fit(func_power, x_data, y_data2)
    
    plt.figure(figsize=(4, 3))
    plt.title('Losses')
    plt.ylabel('Loss')
    plt.xlabel('Epoch')
    plt.scatter(x_data, y_data2, label = 'data')
    plt.plot(x_data, popt[0] * x_data ** popt[1], label = ("$y = {{{}}}x^{{{}}}$").format(round(popt[0],2), round(popt[1],2)))
    plt.plot(x_data, x_data**3, label = '$x^3$')
    plt.legend()
    plt.show()

    REF

    https://stackoverflow.com/questions/53781815/superscript-format-in-matplotlib-plot-legend

     https://stackoverflow.com/questions/21226868/superscript-in-python-plots

  • 相关阅读:
    .NET开发人员如何开始使用ML.NET
    微软开源 Try .NET
    在kubernetes 集群内访问k8s API服务
    微软发布ML.NET 1.0
    现代“十二要素应用”与 Kubernetes
    .NET和Docker ,比翼双飞
    .NET Core 时代已经到了,你准备好了吗
    一份.NET 容器化的调查小结
    容器化时代我们应当选择Kubernetes
    机器学习 ML.NET 发布 1.0 RC
  • 原文地址:https://www.cnblogs.com/emanlee/p/14401039.html
Copyright © 2011-2022 走看看