How to get X-axis values to be vertical

This is probably a silly question but is there an option to see the x-axis values vertically instead of horizontally?

image

1 Like

Hi @medeirov! Welcome to the Streamlit community! :tada: :partying_face: :tada:

That’s a good question and one that I’ve asked before as well. So you’re in good company :wink:

What library are you using to create your plot? It’s fairly straightforward with matplotlib. You can specify a rotation for the x-tick labels in degrees or with keywords. Here are a few illustrative examples:

import streamlit as st
import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [1, 4, 9, 6]
labels = ['Frogs', 'Hogs', 'Bogs', 'Slogs']

fig = plt.figure(figsize=(12, 5))
plt.plot(x, y)

# You can specify a rotation for the tick labels in degrees or with keywords.
plt.xticks(x, labels, rotation='horizontal')
st.pyplot(fig)

rotation='horizontal

rotation='vertical’

rotation=45

Hope this helps! Feel free to reach out with follow-up questions :balloon:

Happy Streamlit-ing!
Snehan

2 Likes

Hi! Thanks a lot for the response.
I was using the standard streamlit (st.bar_chart())
But since that works with matplotlib as well, I’ll just switch to that one.

Thanks, again!

2 Likes

st.bar_chart is a convenience wrapper around st.altair_chart, so that there is a quickstart way to plot the data. But as you’ve noticed, there aren’t any arguments for flipping the axes or doing other customizations. So either switching to matplotlib as @snehankekre showed, Altair or another plotting library will allow you to specify the chart exactly how you want it.

Best,
Randy

2 Likes