Matplotlib 中存在错误的 LogLog 图

问题描述 投票:0回答:1

我想以 LogLog 比例绘制有错误的图。我应该在这里修复什么?据我了解,添加错误的功能并未内置到 loglog 方法中。

x = np.arange(182).astype('float64')
y = np.arange(182).astype('float64')
yerr = np.arange(182).astype('float64')
with open("/home/erg/ch5", "r") as myfiley:
    datay = myfiley.read().splitlines()
with open("/home/erg/ch6", "r") as myfilex:
     datax = myfilex.read().splitlines()
 with open("/home/erg/ch4", "r") as myfilez:
     dataz = myfilez.read().splitlines()
for i in range(len(datax)):
    x[i] = datax[i]
    y[i] = datay[i]
    yerr[i] = dataz[i]
fig, ax = plt.subplots(figsize=(8, 6))
ax.tick_params(axis='both', labelsize=35)
ax.set_title('4RIGHT-ACCIDENT', fontsize=40)
plt.xlabel('AMP', fontsize=35, color='black')
plt.ylabel('COUNTS', fontsize=35, color='black')
ax.loglog(x, y, yerr=yerr, linewidth=5)
plt.show()
python matplotlib plot
1个回答
0
投票

我稍微调整了你的代码,所以它不会读取你的本地文件,但它会绘制模拟数据(np.arange):

from matplotlib import pyplot as plt
import numpy as np

x = np.arange(182)
y = np.arange(182)
yerr = np.arange(182).astype("float64") * 0.1

fig, ax = plt.subplots(figsize=(8, 6))
ax.tick_params(axis='both', labelsize=35)
ax.set_title('4RIGHT-ACCIDENT', fontsize=40)
plt.xlabel('AMP', fontsize=35, color='black')
plt.ylabel('COUNTS', fontsize=35, color='black')
ax.errorbar(x, y, yerr)
# set the x and y scale manually:
ax.set_xscale('log')
ax.set_yscale('log')
plt.show()

与以下内容相比,这是相同的图(但有误差线):

fig, ax = plt.subplots(figsize=(8, 6))
ax.tick_params(axis='both', labelsize=35)
ax.set_title('4RIGHT-ACCIDENT', fontsize=40)
plt.xlabel('AMP', fontsize=35, color='black')
plt.ylabel('COUNTS', fontsize=35, color='black')
ax.loglog(x, y)

© www.soinside.com 2019 - 2024. All rights reserved.