在Python中制作这个图表可视化的最佳方法。

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

如果这是一个不恰当的问题,我很抱歉 - 我是这个网站的新手。

我有一个线图(可以在这里找到。此处),我希望能够在Python中对它进行编程。

如你所见,这是一个没有增量x轴的线图。x轴上有一些方框,每个方框都有一个描述符和一个数字。绘制的点就是上述与每列相关的数字。

我对可视化库Bokeh很熟悉,但似乎无法得出好的结果。Matplotlib也是一个选择,但那个库通常生成的图形相当粗糙。有谁能告诉我,他们以前是否见过这种图表(比如,比 "线图 "更具体的名字)?我唯一真正的限制是,我需要这个图表在网络上很容易呈现,因此我最初看的是Bokeh。欢迎提出任何建议

python data-visualization
1个回答
1
投票

如果我对你的问题理解正确的话,你想要的是一个x轴只有小刻度的线图。

我同意matplotlib看起来很粗糙:我认为Plotly是一个非常友好的库,用于制作交互式的图形,并在网页上很好地渲染。

要在网页上嵌入图形,你可以使用chart_studio库,然后用用户名创建一个Chart Studio账户,并获得你的API密钥。

import plotly as py
import plotly.graph_objects as go 
import chart_studio
import chart_studio.plotly as ch_py
import chart_studio.tools as tls

x_data = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y_data = [3, 5, 3.3, 6.2, 3.5, 4.2, 3.7, 6.3, 4.4]

fig = go.Figure(data = go.Scatter(x = x_data, y = y_data))

fig.update_layout(
    xaxis = dict(
        tickmode = 'array',
        tickvals = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5],
        ticktext = ['str1', 'str2', 'str3', 'str4', 'str5', 'str6', 'str7', 'str8', 'str9'] 
    ),
    yaxis = dict(
        tickmode = 'array',
        tickvals = [1,2,3,4,5,6,7]
    )
)

fig.show()

# create a chartstudio account and generate an API key
# username = 'xxxxxxxx'
# api_key = 'xxxxxxxxxx'

# chart_studio.tools.set_credentials_file(username=username, api_key=api_key)
# ch_py.plot(fig, filename = 'my_filename', auto_open = True)

当你运行它时,它会自动在浏览器中呈现。

enter image description here

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