0

I am looking for a way to clean-up the ticks in my pyplot scatter plot.

To create a scatter plot from a Pandas dataset column with strings as elements, I followed the example in [2] - and got me a nice scatter plot:

pyplot scatter plot with 10k ticks of ~200 unique names

input are 10k data points where the X axis has only ~200 unique 'names', that got matched to scalars for plotting. Obviously, plotting all the 10k ticks on the x axis is a bit clocked. So, I am looking for a way, to print each unique tick only once and not for each data point?

My code looks like:

    fig2 = plt.figure()
    WNsUniques, WNs = numpy.unique(taskDataFrame['modificationhost'], return_inverse=True)
    scatterWNs = fig2.add_subplot(111)
    scatterWNs.scatter(WNs, taskDataFrame['cpuconsumptiontime'])
    scatterWNs.set(xticks=range(len(WNsUniques)), xticklabels=WNsUniques)
    plt.xticks(rotation='vertical')
    plt.savefig("%s_WNs-CPUTime_scatter.%s" % (dfName,"pdf"))

actually, I was hoping that setting the plot x ticks to the unique names should be sufficient - but apparently not? Probably it is something easy, but how do I reduce the ticks for my subplot to unique once (should they not already be uniqueified as returned by numpy.unique?)? Maybe someone has an idea for me?

Cheers ans thanks, Thomas

1 Answer 1

1

You can use the set_xticks method to accomplish this. Note that 200 axis ticks with labels are still quite a lot to force on a small plot like this, and this is what you might already be seeing with the above code. Without complete code to play with, I can't say for sure.

Additionally, what is the size of WNsUniques? That can easily be used to check if your call to unique is doing what you think.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi - yes, I also just realized, that my input dataset contained >500 unique names and not <200 - also with 100 names it really looks crowded. I have to rethink my strategy...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.