0

As a result of the previous code, I have two lists. How can I make a plot with letters from "lab" (one by one) on the X-axis, and corresponding numbers from list val - on the Y axis?

I tried:

lab = ['a', 'b', 'c', 'a', 'b', 'c']
val = [1, 2, 4, 1, 2, 4]

from matplotlib import pyplot as plt

plt.bar(lab, val)

It plots each letter only once.
enter image description here And I want it to plot the whole sequence letter by letter.

KittMedia
  • 7,368
  • 13
  • 34
  • 38
fiskur
  • 3
  • 3

1 Answers1

2

You can use indexes, and then just set the xticks labels like:

lab = ['G', 'U', 'U', 'U', 'U', 'U', 'C', 'A', 'U', 'U', 'U', 'R', 'G', 'C', 'N']
lab_x = [i for i in range(len(lab))]
val = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 4]

from matplotlib import pyplot as plt

plt.bar(lab_x, val)
plt.xticks(lab_x, lab)
cmaureir
  • 285
  • 2
  • 8