#๐Ÿ”’ how to move ticks on the x axis matplotlib

19 messages ยท Page 1 of 1 (latest)

frigid domeBOT
#

@slow gust

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

slow gust
#

Hey im trying to figure out how to move the ticks on the x axis (and their categories). Ive looked at yt, asked chat gpt and looked around in google. no results. itd be great if you can tell me how to move them

honest tusk
#

move where or how?

slow gust
#

like that

twin edge
#

!paste

frigid domeBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

honest tusk
#

this could help you

slow gust
#

cheers ill have a look at it rn

#

heres the code if you want to have a look at it

#

i didnt rlly find it all that much helpful sorry

#

im very new to coding and i have no idea what its talking about

honest tusk
#

I was able to do this:

#

is that what you wanted?

#

here's the code for this one:

import numpy as np
import matplotlib.pyplot as plt

categories = ["cuteness", "Size", "Friendly", "Clever", "Strong"]

plist = [2, 3, 3, 1, 2]        # Pug
glist = [2, 4, 2, 2, 3]        # Golden retriever
dlist = [3, 1, 3, 2, 1]        # Dachshund
clist = [3, 1, 2, 2, 2]        # Chihuahua

bar_width = 0.2 # width of the bars

bar1 = np.arange(len(categories))

# Plotting each group of bars separately with adjusted x-coordinates
plt.bar(bar1 - 0.3, plist, bar_width, label="Pugs", color="red")
plt.bar(bar1 - 0.1, glist, bar_width, label="Golden retriever", color="purple")
plt.bar(bar1 + 0.1, dlist, bar_width, label="Dachshund", color="yellow")
plt.bar(bar1 + 0.3, clist, bar_width, label="Chihuahua", color="brown")

# labels and title
plt.xlabel('Categories')
plt.ylabel('Values')
plt.title('Joint Bar Graph of Dog Ratings')
plt.ylim(0, 5)
plt.xticks(bar1, categories)

ax = plt.gca()

for t in ax.get_xticklabels():
    t.set_ha('right')

plt.legend()
plt.show()
frigid domeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.