Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1006387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:27:08+00:00 2026-05-16T08:27:08+00:00

Anyone know if it is possible to wrap the xtick labels in matplotlib? Right

  • 0

Anyone know if it is possible to wrap the xtick labels in matplotlib? Right now I’ve got the following code (kind of messy — been hacking at it for a while):

def plotResults(request, question_id):
 responses = ResponseOption.objects.filter(question__id=question_id).order_by('order').annotate(response_num=Count('response'))

 counts = []
 labels = [] 

 for response in responses:
  counts.append(response.response_num)
  labels.append(smart_truncate('$'+response.text+'$'))

 N = len(labels)
 labels = tuple(labels)
 counts = tuple(counts)
 ind = na.array(range(N))+0.5
 width = .35
 fig = Figure(facecolor='white',edgecolor='white')
 ax = fig.add_subplot(1,1,1)


 rects1 = ax.bar(ind, counts,linewidth=0)

 ax.set_ylabel('$Count$')

 ax.set_title('$Response Historgram$')
 ax.set_xticks(ind+width)
 ax.set_xticklabels(labels)

 print mpl.matplotlib_fname()

 canvas = FigureCanvas(fig)
 response = HttpResponse(content_type='image/png')

 canvas.print_png(response)

 return response

That generates this plot:

alt text

As you can see the xticks are boned. Any ideas on how to wrap them, or baring that make them readable? Thanks again!

PS: This is part of a Django project. I return the plot as a png image — normally call them from img tags in various views.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:27:09+00:00Added an answer on May 16, 2026 at 8:27 am

    Perhaps try:

    ax.set_xticklabels(labels, rotation=45)
    

    Thanks to Amro for pointing out that rotation can be any degree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's the ABI versions table; the default value for the… May 16, 2026 at 5:40 pm
  • Editorial Team
    Editorial Team added an answer Try DebugBar - It's free for personal use. Then there… May 16, 2026 at 5:40 pm
  • Editorial Team
    Editorial Team added an answer You can use defauldict, like this: >>> import collections >>>… May 16, 2026 at 5:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Does anyone know if it's possible to host a SQL server in the cloud
Anyone know if it's possible to move the HomeController and Home related views into
Does anyone know if it's possible to selected multiple days with swingx's jxdatepicker? I'm
does anyone know if it's possible to run T4 template file from another T4
is it possible to start a context menu on the onCreate method? I know
Does anyone know of a tutorial on how to read data from a server
Does anyone know what the performance difference is between Java NIO vs DotNet IO
I know that it's faster to do the following: var $header = $(#header); $header.css({color:#ff0000});
I have a string input that i do not know whether or not is
Possible Duplicate: How do I calculate relative time? I want to format dates on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.