【发布时间】:2023-03-12 23:40:01
【问题描述】:
Plotly.py 的 y 轴有问题。数据未排序。即使在 csv 文件中,数据也是按升序排序的。 https://i.stack.imgur.com/SUOL3.png
import plotly
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
import numpy as np
import math
#What is the filename
filename = 'output.csv'
#What is the X Value?
xvalue = 'total_students'
#What is the Y Value?
yvalue = 'realcount'
#What is the plot title?
PlotTitle = 'total_students'
filename = input("What is the filename? (WITH .CSV) ")
xvalue = input("What is the X value? ")
yvalue = input("What is the y Value? ")
PlotTitle = input("What is the title of this chart? ")
esc1 = pd.read_csv('output.csv', encoding='cp1252')
def random_color():
rgbl=[255,0,0]
random.shuffle(rgbl)
return tuple(rgbl)
esc1 = go.Scatter(
x = esc1[xvalue],
y = esc1[yvalue],
name = 'School',
mode = 'markers',
marker = dict(
size = 10,
sizemode='area',
sizeref=1,
color = 'rgba(66, 134, 244, .8)'
)
)
data = [esc1]
layout = dict(title = 'Total Student Scatter',
yaxis = dict(zeroline = True,
title=yvalue),
xaxis = dict(zeroline = True,
title=xvalue)
)
#fig = dict(data=data, layout=layout)
#py.iplot(fig, filename='styled-scatter')
plotly.offline.plot({
"data": data,
"layout": layout
},filename=PlotTitle+'.html', auto_open=False)
print("Finished")
Jeeze stack-overflow 有大量的质量控制。我必须继续添加细节,所以我希望这会有所帮助。
【问题讨论】:
-
我没有足够的代表来嵌入图像。对不起!
-
您也可以发布您的代码吗?
-
@TorinMay 我们开始吧。
-
欢迎来到 Stackoverflow!看看minimal reproducible example。如果没有看到原始数据,真的很难猜出根本问题是什么。
标签: python pandas csv plot plotly