Good evening! Question from kindergarten, but still.

I build the simplest graph:

import matplotlib.pyplot as plt import random as r example = {"mm1":{"x":[0,1,2,3], "y":[0,1,2,3]}, "mm2":{"x":[0,1,2,3], "y":[4,5,6,10]}} for m,i in example.items(): plt.title(m) plt.plot(i["x"], i["y"], "b") plt.grid(True, linestyle='-', color='0.75') plt.show() 

Accordingly, I get

Is it possible, instead of the numerical values ​​of the scale X, to display aliases?

Not [0.0, 0.5, 1.0 ...] but [A, B, C, D]. I'm not interested in a column chart, where each column can be given a name.

  • Something tells me that it will be much more convenient for you to work with the Pandas module . - MaxU

1 answer 1

It is possible so:

 plt.xticks(example['mm1']['x'], list('ABCD')) 

Result:

enter image description here


Pandas Example:

 df = pd.DataFrame({'mm1':example['mm1']['y'], 'mm2':example['mm2']['y']}, \ index=list('ABCD')) 

The resulting DataFrame:

 In [413]: df Out[413]: mm1 mm2 A 0 4 B 1 5 C 2 6 D 3 10 

Plotting:

 df.plot(grid=True) 

Result:

enter image description here