Matplotlib x_ticks font set

How would I set the x_axis labels at indices 1,2,3 .... n to be something else.

lam_beta = [(lam1,beta1),(lam1,beta2),(lam1,beta3),....(lam_n,beta_n)]
chunks = [chunk1,chunk2,...chunk_n]
ht_values_per_chunk = {chunk1:[val1,val2,...],chunk2:[val1,val2,val3,.....]...}
color='rgbycmk'
     j=0
     for chunk in chunks:
        plt.plot([hr_values_per_chunk[chunk][i] for i,item in enumerate(lam_beta)],[i for i,item in enumerate(lam_beta)],color=j%len(color))
        j+=1

     plt.set_xticks([i for i,item in enumerate(lam_beta)])
     plt.set_xticklabels([item for item in lam_beta],rotation='vertical')
     plt.show()

Mistake:

AttributeError: the 'module' object does not have the 'set_xticks' attribute

Here I cannot set the values ​​of the lambda_beta tuple as the values ​​of each tick on the x axis, since it says that plt does not have such a method. How can I achieve this for plt? I used xticks because I did it this way by creating a histogram in matplotlib. Any help would be greatly appreciated. Thank you in advance!

+4
source share
1 answer

set_xticks set_xticklabels , plt. , 'module' object has no attribute 'set_xticks'.

,

[i for i,item in enumerate(lam_beta)]

range(len(lam_beta))

[item for item in lam_beta]

lam_beta

axes - plt.subplots:

:

fig, ax = plt.subplots()
...
ax.set_xticks(range(len(lam_beta)))
ax.set_xticklabels(lam_beta, rotation='vertical')

ax axes. axes - - matplotlib.


pylab Matlab, plt.xticks.

loc = range(len(lam_beta))
labels = lam_beta

plt.xticks(loc, labels, rotation='vertical')

fig, ax = plt.subplots()
ax.set_xticks(loc)
ax.set_xticklabels(labels, rotation='vertical')

plt.xticks .


[hr_values_per_chunk[chunk][i] for i,item in enumerate(lam_beta)]

hr_values_per_chunk[chunk][:len(lam_beta)]

color ax.plot ax.set_color_cycle:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
lam_beta = [(lam1,beta1),(lam1,beta2),(lam1,beta3),....(lam_n,beta_n)]
chunks = [chunk1,chunk2,...chunk_n]
ht_values_per_chunk = {chunk1:[val1,val2,...],chunk2:[val1,val2,val3,.....]...}
color='rgbycmk'
ax.set_color_cycle(colors)

for chunk in chunks:
    vals = hr_values_per_chunk[chunk][:len(lam_beta)]
    ax.plot(vals, range(len(lam_beta)))

ax.set_xticks(range(len(lam_beta)))
ax.set_xticklabels(lam_beta, rotation='vertical')
plt.show()
+11

All Articles