What am i doing wrong with matplotlibs yticks?

2024/11/18 19:51:44

My code is as follows (dont ask for the variable names, im german^^):

import matplotlib.pyplot as plt
import numpy as np strecke = []
zeit = []daten = open("BewegungBeschleunigung.csv")for i in daten:i =  i.strip().split(",")strecke.append(i[1])zeit.append(i[0])zeit.pop(0)
strecke.pop(0)f, ax = plt.subplots()ax.set_xticks(np.arange(0, 100 + 1, 5)) 
ax.set_yticks(np.arange(0,6000, 10))
ax.set_xlabel("Zeit")
ax.set_ylabel("Strecke")plt.plot(zeit, strecke, "go")
#plt.autoscale(enable = False, axis = "both", tight = None)
plt.grid(True)
plt.show()

Now my Question is: As you can see in the picture , the y-axis only goes to 4860 instead of 6000 which is what I wrote and not in 10 steps (as what I wanted). It just goes in random steps. What am I doing wrong and why doesn't the x-axis go to 100?

thanks for your help.

enter image description here

Answer

I had the same issue and after some hours I've found that my values were strigs:

ypoints=['97', '100', '98', '99', '55', '97', '100', '98', '100', '100', '100', '100', '100', '98', '100', '100']

I only did the following:

ypoints = [int(y) for y in ypoints]
https://en.xdnf.cn/q/118640.html

Related Q&A

Python- How to implement quick sort when middle element is the pivot?

There are many different versions of quickSort that pick pivot in different ways.Always pick the first element or the last element as the pivot Pick a random element as a pivot. Pick median as the pivo…

How to expose a form when a radio button is checked?

Consider the following sample html template,<html><body><input type="radio" name="x">x</input><br><input type="radio" name="y"&g…

How to generate perlin noise in pygame?

I am trying to make a survival game and I have a problem with perlin noise. My program gives me this:But I want something like islands or rivers. Heres my code: #SetUp# import pygame, sys, random pygam…

Inputting range of ports with nmap optparser

This is the scriptimport nmap import optparsedef nmapScan(tgtHost,tgtPort):nmScan = nmap.PortScanner()nmScan.scan(tgtHost,tgtPort)state=nmScan[tgtHost][tcp][int(tgtPort)][state]print "[*] " +…

Implementing a Python algorithm for solving the n-queens problem efficiently

I am working on a project that requires me to solve the n-queens problem efficiently using Python. I have already implemented a basic recursive algorithm to generate all possible solutions, but I am lo…

Annotations with pointplot

I am using a pointplot in seaborn.import seaborn as sns sns.set_style("darkgrid") tips = sns.load_dataset("tips") ax = sns.pointplot(x="time", y="total_bill", hu…

How do I get data in tuples and tuples in lists?

I am trying to figure out the route that a car takes in a fictional manhattan. I have defined the starting position, being(1,2)(in a 2 dimensional grid).manhattan=[[1, 2, 3, 4, 5],[6, 7, 8, 9, 10],[11…

How to return a value from a table or dataframe given 2 inputs? Python

Lets say this is my dataframe:and the user inputs B and 2Then the function would return clemintineIs there a way to do this without using a bunch of if elif statements. The actual dataframe Im working …

tkinter progressbar for multiprocessing

I have a program that encrypts files and I used multiprocessing to make it faster, but I am having trouble with the tkinter progress bar. I have implemented it but it completes immediately or lags in b…

How to add and subtract in python

So I am making a statcalc and everything is working except adding. When I select the option to add it just skips it and says select an option. I was wondering whats wrong with it?numberstoadd = input(…