来自 Plotly Contour 的 x 轴标签在 python 环境中做了奇怪的事情,但在 Anaconda 中没有

x-axis labeling from Plotly Contour does strange things in python enviroment but not in Anaconda

我正在尝试使用 Plotly Contour as a static image 创建图表。我在 Anaconda 中测试了所有内容,并且效果非常好。然后我将它转移到我的程序中,x 轴标签变得很奇怪。一方面,它是重复的。所以它纵横交错,小数点后位无限多,而且不合时宜。起初,我更新了所有 python 副包,当那没有帮助时,我将求解器更改为 Anaconda 的 Python,但也没有帮助。

def power_calc_graf():
# Create List for Plot
x_axes_range = 5
y_axes_range = 5
deg_plot = 0
deg_end = 2.5
v_2_plot = 0
v_2_end = 2
x_axes = [[] for y in range(y_axes_range + 1)]
y_axes = []
area = [[] for x in range(y_axes_range+1)]
for y in range(y_axes_range + 1):
    for x in range(x_axes_range + 1):
        # print('x/y = ' + str(x) + '/' + str(y))
        v_2_plot = x * (v_2_end / x_axes_range)
        x_axes[y].append(v_2_plot)
        area[y].append(power_calc(v_1_par=v_2_plot, v_2_par=v_2_plot, t_1_par=0, t_2_par=0, deg_par=deg_plot)[9][2])
    deg_plot = round((y * (deg_end / y_axes_range)), 4)
    y_axes.append(deg_plot)

# Plot the List
fig = go.Figure(data=go.Contour(z=area, x=x_axes, y=y_axes, contours_coloring='lines',
        line_width=2,
        contours=dict(start=0, end=area[y_axes_range - 1][x_axes_range - 1], size=1000,
        coloring='heatmap', showlabels=True,
        labelfont=dict(size=12, color='white')),
        colorbar=dict(
            title='Power in W',  # title here
            titleside='right',
            titlefont=dict(
                size=14,
                family='Arial, sans-serif')
            )
        ))
#))

# Export Image
if not os.path.exists("images"):
    os.mkdir("images")

fig.write_image("images/Power_over_Slope_and_Speed.jpeg")
fig.write_image("images/Power_over_Slope_and_Speed.pdf")
  1. 外观 (Python):
  2. 它应该是什么样子 (Anaconda):

我知道代码很乱,因为我写的时间不长,但我愿意学习。 谁能帮帮我?

我现在自己找到了解决办法。我没有在轴声明中传递列表,而是传递嵌套列表。这导致了这种不寻常的行为。将参数 x=x_axes 更改为 x=x_axes[0] 解决了问题。

import plotly.graph_objects as go
fig = go.Figure(data=go.Contour(z=area, x=x_axes[0], y=y_axes, #contours_coloring='lines',
        #line_width=2,
        contours=dict(start=0, end=area[y_axes_range - 1][x_axes_range - 1], size=1000,
        #coloring='heatmap',
        showlabels=True,
        labelfont=dict(size=12, color='white')),
        colorbar=dict(
            title='Power in W',  # title here
            titleside='right',
            titlefont=dict(
                size=14,
                family='Arial, sans-serif')
            )
        ))