python绘制双对数曲线,python画自定义函数曲线

发布时间:2022-11-17

本文目录一览:

1、请问用python处理excel数据绘制曲线图能不能做成一个类似的小软件? 2、如何使用Python绘制光滑实验数据曲线 3、怎样用python画对数图 4、Python如何画函数的曲线 5、python 怎么画与其他方法进行比较的ROC曲线? 6、怎么用python绘图

请问用python处理excel数据绘制曲线图能不能做成一个类似的小软件?

可以啊,先确定好需要操作excel的哪些动作,用到哪些函数,然后通过python调用excel接口,实现对excel的操作;还有一种是只是读取excel里面的数据,然后通过matplotlib等第三方库,绘制数据曲线图。

如何使用Python绘制光滑实验数据曲线

楼主的问题是否是“怎样描绘出没有数据点的位置的曲线”,或者是“x在某个位置时,即使没有数据,我也想知道他的y值是多少,好绘制曲线”。这就是个预测未知数据的问题。 传统的方法就是回归,python的scipy可以做。流行一点的就是机器学习,python的scikit-learn可以做。 但问题在于,仅由光强能预测出开路电压吗(当然,有可能可以预测。)?就是你的图1和图2的曲线都不能说是不可能发生的情况吧,所以想预测开路电压值还需引入其他影响因子。这样你才能知道平滑曲线到底应该像图1还是图2还是其他样子。 如果是单因子的话,从散点图观察,有点像 y = Alnx + B,用线性回归模型确定A,B的值就可以通过x预测y的值,从而绘制平滑的曲线了。

怎样用python画对数图

1、用python画出log1.5(x),log(2x),log(3x)

import numpy as np
import math
import matplotlib.pyplot as plt
x = np.arange(0.05, 3, 0.05)
y1 = [math.log(a, 1.5) for a in x]
y2 = [math.log(a, 2) for a in x]
y3 = [math.log(a, 3) for a in x]
plot1 = plt.plot(x, y1, '-g', label="log1.5(x)")
plot2 = plt.plot(x, y2, '-r', label="log2(x)")
plot3 = plt.plot(x, y3, '-b', label="log3(x)")
plt.legend(loc='lower right')
plt.show()

2、输出结果

Python如何画函数的曲线

输入以下代码导入我们用到的函数库。

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 5, 0.1)
y = np.sin(x)
plt.plot(x, y)

采用刚才代码后有可能无法显示下图,然后在输入以下代码就可以了:

plt.show()

python 怎么画与其他方法进行比较的ROC曲线?

使用sklearn的一系列方法后可以很方便的绘制处ROC曲线,这里简单实现以下。 主要是利用混淆矩阵中的知识作为绘制的数据(如果不是很懂可以先看看这里的基础):

  • tpr(Ture Positive Rate):真阳率 图像的纵坐标
  • fpr(False Positive Rate):阳率(伪阳率) 图像的横坐标
  • mean_tpr:累计真阳率求平均值
  • mean_fpr:累计阳率求平均值
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
from sklearn.metrics import roc_curve, auc
from sklearn.model_selection import StratifiedKFold
iris = datasets.load_iris()
X = iris.data
y = iris.target
X, y = X[y != 2], y[y != 2]  # 去掉了label为2,label只能二分,才可以。
n_samples, n_features = X.shape
# 增加噪声特征
random_state = np.random.RandomState(0)
X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]
cv = StratifiedKFold(n_splits=6)  # 导入该模型,后面将数据划分6份
classifier = svm.SVC(kernel='linear', probability=True, random_state=random_state)  # SVC模型 可以换作AdaBoost模型试试
# 画平均ROC曲线的两个参数
mean_tpr = 0.0  # 用来记录画平均ROC曲线的信息
mean_fpr = np.linspace(0, 1, 100)
cnt = 0
for i, (train, test) in enumerate(cv.split(X, y)):  # 利用模型划分数据集和目标变量 为一一对应的下标
    cnt += 1
    probas_ = classifier.fit(X[train], y[train]).predict_proba(X[test])  # 训练模型后预测每条样本得到两种结果的概率
    fpr, tpr, thresholds = roc_curve(y[test], probas_[:, 1])  # 该函数得到伪正例、真正例、阈值,这里只使用前两个
    mean_tpr += np.interp(mean_fpr, fpr, tpr)  # 插值函数 interp(x坐标,每次x增加距离,y坐标) 累计每次循环的总值后面求平均值
    mean_tpr[0] = 0.0  # 将第一个真正例=0 以0为起点
    roc_auc = auc(fpr, tpr)  # 求auc面积
    plt.plot(fpr, tpr, lw=1, label='ROC fold {0:.2f} (area = {1:.2f})'.format(i, roc_auc))  # 画出当前分割数据的ROC曲线
plt.plot([0, 1], [0, 1], '--', color=(0.6, 0.6, 0.6), label='Luck')  # 画对角线
mean_tpr /= cnt  # 求数组的平均值
mean_tpr[-1] = 1.0  # 坐标最后一个点为(1,1) 以1为终点
mean_auc = auc(mean_fpr, mean_tpr)
plt.plot(mean_fpr, mean_tpr, 'k--', label='Mean ROC (area = {0:.2f})'.format(mean_auc), lw=2)
plt.xlim([-0.05, 1.05])  # 设置x、y轴的上下限,设置宽一点,以免和边缘重合,可以更好的观察图像的整体
plt.ylim([-0.05, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')  # 可以使用中文,但需要导入一些库即字体
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.show()

怎么用python绘图

你可以使用numpy和matplotlab这两个库来实现的你功能。 你的图可以参考:

import matplotlib
from numpy.random import randn
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
def to_percent(y, position):
    # Ignore the passed in position. This has the effect of scaling the default
    # tick locations.
    s = str(100 * y)
    # The percent symbol needs escaping in latex
    if matplotlib.rcParams['text.usetex'] == True:
        return s + r'$\%$'
    else:
        return s + '%'
x = randn(5000)
# Make a normed histogram. It'll be multiplied by 100 later.
plt.hist(x, bins=50, normed=True)
# Create the formatter using the function to_percent. This multiplies all the
# default labels by 100, making them all percentages
formatter = FuncFormatter(to_percent)
# Set the formatter
plt.gca().yaxis.set_major_formatter(formatter)
plt.show()

最主要的就是x轴和y轴的处理,我按照对数算了一下你提供的数据,好像和这个图效果不一样。 如果解决了您的问题请采纳! 如果未解决请继续追问