clstaudt
clstaudt

Reputation: 22498

Axis labelling with matplotlib too sparse

Matplotlib tries to label the ticks on this x-axis intelligently, but it is a little too sparse. There should be a label for 0 and maybe one for 10 and 100.

enter image description here

This is the code which produces the figure. How can I make the labelling on the x-axis more verbose?

   def timePlot2(data, saveto=None, leg=None, annotate=False, limits=timeLimits, labelColumn="# Threads", valueColumn="Average (s)", size=screenMedium):
        labels = list(data[labelColumn])
        figure(figsize=size)
    ax = gca()
    ax.grid(True)
    xi = range(len(labels))
    rts = data[valueColumn] # running time in seconds
    ax.scatter(rts, xi, color='r')
    if annotate:
        for i,j in zip(rts, xi):
            ax.annotate("%0.2f" % i, xy=(i,j), xytext=(7,0), textcoords="offset points")

    ax.set_yticks(range(len(labels)))
    ax.set_yticklabels(labels)
    ax.set_xscale('log')
    plt.xlim(limits)
    if leg:
        legend(leg, loc="upper left", fontsize=10)
    else:
        legend([r"$t$"], fontsize=10)
    plt.draw()
    if saveto:
        plt.savefig(saveto, transparent=True, bbox_inches="tight")

Upvotes: 1

Views: 1689

Answers (1)

ala
ala

Reputation: 224

You can define your own X-Axis-Ticks together with their labels using ax.set_xticks(), in your example

ax.set_xticks((10,100,1000))

should do the trick.

If you like to keep the 10^x-labels, you can add the labels explicitly:

ax.set_xticks((10,100,1000),('$10^1$','$10^2$','$10^3$'))

Upvotes: 2

Related Questions