绘制等高线图和轴标签位置

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

我有一个等高线图,x 轴文本显示在顶部。我试图将其移动到图表的底部,就像任何正常的散点图一样。我尝试了“position:0”和“position:1”,如https://plotly.com/python/reference/layout/xaxis/所示,但无济于事。

有人知道我还可以尝试什么吗?

Contour plot

代码:

import pandas as pd
import plotly.graph_objects as go
import numpy as nump

# variables are initialised with x,y co-ordinates
cordof_x = nump.arange(0, 10, 0.2)
cordof_y = nump.arange(0, 10, 0.2)

# Colourscale
colorscale = [[0, '#FFC0CB'], [0.5, 'rgb(120,120,120)'], [1, '#0000FF']]

# A mesh is created with the given co-ordinates by this numpy function
[X, Y] = nump.meshgrid(cordof_x, cordof_y)
contour_function = nump.cos((X + 6) * (1 / 10)) + nump.sin((Y) * (-1 / 10))

contour_trace = go.Contour(x=cordof_x, y=cordof_y, z=contour_function, showscale=False, ncontours=40, colorscale=colorscale, hoverinfo='skip')
scatter_trace = go.Scatter(x=[8], y=[5], mode='markers', marker=dict(symbol='star-diamond-dot', color="#FFBF00", size=24, line=dict(color="black", width=3)))

contour_plot = go.Figure(data=[contour_trace, scatter_trace])
contour_plot.update_layout({
    "showlegend": False, "height":300, "width":300,
    "xaxis": {"title_text": "CategoryA", 'title_font': {"size": 22, "color": "black"}, "showticklabels": False, "dtick": 1, "range": [0, 10], "position":0},
    "yaxis": {"title_text": "CategoryB", 'title_font': {"size": 22, "color": "black"}, "showticklabels": False, "dtick": 1, "range": [0, 10]},
    "autosize": True, "plot_bgcolor": "rgba(0, 0, 0, 0)", "paper_bgcolor": "white", "margin": dict(l=0, r=0, b=0, t=0)})
contour_plot.show()
plotly axis contour plotly-python axis-labels
1个回答
0
投票

这是由旧版本的

plotly
造成的。 5.20以上版本该问题已解决。 检查您的版本:

import plotly
print(plotly.__version__)
© www.soinside.com 2019 - 2024. All rights reserved.