Question

Can't get my simple intention of plotting 2 lists working. The length of the 1dim-lists are both the same and the list-values are simple floats with just digits after the comma. The long variable names may be suspect, since I've researched some cases where pyplot didn't like certain names. Anyway, the code looks like this (the list itself is printed + copypasted by me):

countErrXPercent_allX_ABC = [0, 0.0, 0.0, 4.55, 5.41, 15.69, 23.44, 29.27, 32.05, 47.95, 48.0, 64.91, 43.94, 57.35, 52.27, 70.59, 79.55, 73.53, 77.14, 64.52, 77.78, 80.0, 82.61, 72.0, 86.96, 74.07, 77.78, 66.67, 60.0, 55.56, 80.0, 90.91, 77.78, 75.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, -1.0, 100.0, 100.0]
countErrYPercent_allY_ABC = [0, -1.0, 0.0, 10.0, 12.5, 22.22, 43.59, 48.61, 53.42, 67.37, 71.83, 78.65, 74.32, 72.88, 68.97, 82.69, 88.37, 77.27, 84.62, 85.0, 86.67, 90.0, 93.94, 83.33, 87.5, 80.95, 83.33, 92.86, 83.33, 57.14, 81.82, 100.0, 75.0, 100.0, 100.0, 60.0, 100.0, 50.0, 83.33, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
P.plot(countErrXPercent_allX_ABC, '.', 'b', label='aErr < bErr')
P.plot(countErrYPercent_allY_ABC, '.', 'r', label='aErr < cErr')
P.show()

Error message:

Traceback (most recent call last):
File "xyz.py", line 169, in errClassesX
P.plot(countErrXPercent_allX_ABC, '.', 'b', label='aErr < bErr')
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\pyplot.py", line 2817, in plot
ret = ax.plot(*args, **kwargs)
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.py", line 3996, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.py", line 330, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.py", line 308, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Program Files (x86)\Python\lib\site-packages\matplotlib\axes.py", line 248, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension

The confusing thing is that when printing those lists + copypasting it in a new empty file (with new variables 'l' and 'k', pyplot works. I tried to plot duplicates (copy.copy() command) of the lists and assigning new varNames, but unfortunately without success. Therefore, any idea is highly appreciated.

Was it helpful?

Solution

You are fomatting the formatting string wrong, it should be:

plt.plot(countErrXPercent_allX_ABC, '.b', label='aErr < bErr')

As you have it it is trying to plot '.' against your list.

It is also conventional to import pyplot as plt, not P.

import matplotlib.pyplot as plt

Doing this will make your code easier for others to read and will make re-using example code easier on you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top