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

  • Home
  • SEARCH
  • 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 6352113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:08:25+00:00 2026-05-24T22:08:25+00:00

Being a newbie to using matplotlib ,I was trying out some code ,from examples

  • 0

Being a newbie to using matplotlib ,I was trying out some code ,from examples I found on the net.I was using a lot of constants to adjust the dimensions of the plot elements.I found that I am at a loss ,when it came to naming the constants properly.

for example when creating a bar chart from a pair of x_list and y_list

to scale the figure width

DIVISION_CONSTANT = 4
width_scale = len(y_list)/DIVISION_CONSTANT
size_of_figure = (8*width_scale,6)
figure = pylab.figure(figsize = size_of_figure)
...

to restrict the ylimit and the number of yticks

ANOTHER_DIVISION_CONSTANT = 10
max_y = max(ylist)
step = max_y/ANOTHER_DIVISION_CONSTANT
...
ax.set_yticks(range(0,max_y+ystep,ystep))
ax.set_ylim(0,max_y+ystep)

and while setting the distance of xlimits from the origin

DISTANCE_FROM_ORIGIN = .5
ax.set_xlim([min(xlist) - DISTANCE_FROM_ORIGIN, max(xlist) + DISTANCE_FROM_ORIGIN])
...

Can someone give better names for these constants?I couldn’t find the technical names for them in any book or tutorial..and trying to think up some on my own seems silly..

Also,when the axes.bar() function is called ,

ax.bar(xlist, ylist, width=BAR_WIDTH,align='center',color='yellow')

I tried to give several values for BAR_WIDTH (.5,1,1.5..) and found that .5 causes a bar to occupy half the space between 2 xticks

A value of 1 causes all bars to touch each other

1.5 causes bars to overlap.

So,what is the meaning of this numerical value? does it represent some percentage of space between two xticks?

  • 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-24T22:08:26+00:00Added an answer on May 24, 2026 at 10:08 pm

    First, I find that plotting figures is generally a messy business and often my code just does not look nice. It has become better over the years but in the end, to get a production-grade plot there will always be hand tweaking. And this will include many constants which probably don’t have ‘proper’ names, like the ones you use above. As always, just try to give them useful names. So I’d call them

    DIVISION_CONSTANT --> width_scale
    width_scale --> fig_width
    ANOTHER_DIVISION_CONSTANT  --> step_scale
    DISTANCE_FROM_ORIGIN --> x_limits
    

    but that is just a matter of taste, not right or wrong. (Don’t use uppercase but that was presumably just used here for presentation purposes).

    Then, the width parameter of the plt.bar plot is in the units of your xlist not percent.

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

Sidebar

Related Questions

I'm probably doing something wrong, being a newbie. Could you please help me out?
I have a simple code to fetch users from db using sqlalchemy and return
I want to prevent the # from being used because I'm using jQuery to
Being a total newbie with Objective-C coming from C#, I keep finding conflicting info
Being a newbie I have read forums and posts but still can't work out
As being quite a newbie in linux, I have the follwing question. I have
Being relatively new to the .net game, I was wondering, has anyone had any
Being a Windows developer I'm currently working on my own project using LAMP. I
being the C# newbie that I undoubtedly am, I'm a bit confused that you
I'm a complete newbie to Objective-C, coming from a background of PHP, assorted dialects

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.