
Полный код графика показан здесь:
Код: Выделить всё
def plot(Xmin, Xmax):
datafile = '' # Placeholder for the data file path
try:
data = np.loadtxt(datafile)
xmin = data[:, 0]
xmax = data[:, 1]
yvalue = data[:, 2]
yerror = data[:, 3]
zvalue = data[:, 4]
upperBound = data[:, 5]
# Compute the midpoint of the x-axis
x = np.sqrt(xmin * xmax)
xerr = np.array([x - xmin, xmax - x])
# Compute y-axis values
y = x**2 * yvalue / (xmax - xmin)
yerr = x**2 * yerror / (xmax - xmin)
y_ul = x**2 * upperBound / (xmax - xmin)
y_ulerr = np.array([0.5 * y_ul, [0] * len(y)])
# Create the plot
fig, ax = plt.subplots()
# Plot the data points where z > 9
ax.errorbar(x[zvalue > 9], y[zvalue > 9], xerr=xerr[:, zvalue > 9], yerr=yerr[zvalue > 9],
fmt='.k', color='blue', label='Detected', markersize=12)
# Plot upper limits where z < 9, in red
ax.errorbar(x[zvalue < 9], y_ul[zvalue < 9], xerr=xerr[:, zvalue < 9], yerr=y_ulerr[:, zvalue < 9],
fmt='.k', color='red', uplims=True, label='Upper Limit', markersize=12)
# Set axis limits and scales
ax.set_xlim(a,b)
ax.set_ylim(c, d)
ax.set_xscale('log')
ax.set_yscale('log')
# Set axis labels with bold font
ax.set_xlabel(r'X [units]', fontweight='bold')
ax.set_ylabel(r'Y [units]', fontweight='bold', fontsize=9)
# Plot z-values on a secondary axis
ax2 = ax.twinx()
ax2.bar(x, zvalue, width=(xmax - xmin), color='gray', edgecolor='gray', alpha=0.5)
ax2.set_ylim(bottom=0)
ax2.set_xscale('log')
ax2.set_ylabel('Z value', fontweight='bold')
# Return the file paths (placeholders)
return png_file, pdf_file
except Exception as e:
print(f"An error occurred: {e}")
Подробнее здесь: https://stackoverflow.com/questions/789 ... per-limits