Hello guys, I am sry for the question I read multiple questions in this forum but didn’t understand how to fix my problem. My problem is that I got an csv file from which I collect data for my x-axis and y-axis. The Data looks like this:
141954,23.750
14200,23.750
14206,23.750
142012,23.750
142018,23.750
142023,23.750
The values iafter the ‘,’ are the x-values. So you see all have the same value. When I want to plot this with the following code:
from dash import Dash, html, dcc
from os.path import isfile, join
from dash.dependencies import Input, Output
import os
import plotly.graph_objs as go
mypath = '/Users/theo/Documents/Privat/Arbeiten/HiWi-Stelle/Modul-Vorbereitung/TCPServer/'
onlyfiles = [f for f in os.listdir(mypath) if isfile(join(mypath, f))]
onlyfiles.remove("TCPServer.py")
onlyfiles.remove(".DS_Store")
formatted_files = []
for file in onlyfiles:
year = file[0:4]
month = file[4:6]
day = file[6:8]
formatted_files.append(year + "." + month + "." + day)
app = Dash(__name__)
app.layout = html.Div([
html.Div(children='Temperature Plot'),
dcc.Dropdown(id='file-dropdown', options=formatted_files, placeholder="Select a file"),
dcc.Graph(id='graph')
])
@app.callback(
Output('graph', 'figure', allow_duplicate=True),
Input('file-dropdown', 'value'),
prevent_initial_call=True
)
def update_graph(selected_file):
row1_list = []
row2_list = []
if selected_file:
file = str(selected_file).replace(".", "") + ".csv"
file_path = os.path.join(mypath, file)
with open(file_path, 'r') as f:
for line in f:
if line != "\n":
split = line.split(",")
row1_list.append(split[0])
row2_list.append(split[1])
col1_cleaned = [element.strip() for element in row1_list]
col2_cleaned = [element.strip() for element in row2_list]
integer_col1 = [int(x) for x in col1_cleaned]
float_col2 = [float(x) for x in col2_cleaned]
float_col2 = [y + i * 0.01 for i, y in enumerate(float_col2)]
fig = {
'data': [go.Scatter(
x=integer_col1,
y=float_col2,
mode='markers', # Modus auf 'markers' setzen, um ein Punkt-Diagramm zu erstellen
marker=dict(size=10) # Größe der Punkte festlegen
)
],
'layout': {'title': 'Graph of ' + selected_file}
}
return fig
else:
return {}
if __name__ == '__main__':
app.run(debug=True)
Question
then all works finde except that no graph is shown. So dash got a problem when some values have the same x-value? Why this?
My Solution
an ugly solutionn from my side was to edit the values like a little bit with:
float_col2 = [y + i * 0.01 for i, y in enumerate(float_col2)]