0

So I'm trying to make a graph tool in python with plotly where the user enters data for the x and y axes and it produces a graph based on the data. However, when I enter data and it produces the graph, the x and y axes don't have consistent intervals. Does anyone know how I can make the intervals consistent so the graph is actually correct? Thanks in advance.

My code:

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

dataNum = int(input('How many items do you want on the x and y axis? '))

xAxis = []
yAxis = []

for i in range(dataNum):
    x = input('What number would you like to enter on the x axis? ')
    y = input('What number would you like to enter on the y axis? ')
    print('\n')

xAxis.append(x)
yAxis.append(y)

userData = {'X axis' : xAxis, 'Y axis' : yAxis}
df = pd.DataFrame(userData)
print(df)

data = [go.Scatter(x = df['X axis'], y = df['Y axis'])]

graph = go.Figure(data)

graph.show()

Here is an example of what I'm talking about
enter image description here

Mr. T
  • 11,960
  • 10
  • 32
  • 54
  • You plot strings. `input()` always returns strings, and strings are plotted as categorical variables against an index (1, 2, 3...). `x = float(input(...))` is the solution. – Mr. T Feb 15 '22 at 22:24
  • @Mr.T it worked thank you so much! I don't know how I didn't realise this but thanks for your help – Josh_Stigzelius Feb 16 '22 at 18:58
  • Don't worry, we all have been there. On the plus side: Now you will never forget this lesson. – Mr. T Feb 16 '22 at 19:07

0 Answers0