Issue
I have the following two dummy dfs:
# First df
columns_One = ['count']
data_One = [[1],
[100],
[100],
[100],
[120],
[500],
[540],
[590]]
dummy_One = pd.DataFrame(columns=columns_One, data=data_One)
# Second df
columns_Two = ['count']
data_Two = [[1],
[100],
[102],
[300],
[490],
[400],
[400],
[290]]
dummy_Two = pd.DataFrame(columns=columns_Two, data=data_Two)
I want to plot them as a histogram. It currently looks like this:
How I plot it:
fig, axes = pyplot.subplots(1,2)
dummy_One.hist('count', ax=axes[0])
dummy_Two.hist('count', ax=axes[1])
pyplot.show()
I am struggling with the following:
- How can I change the y with the x axis?
- How can I set an universal y label and x label for both charts?
- How can I set the range for the y and x axis for both charts?
Solution
I assume that you simply want to rotate the plot, add
orientation="horizontal"
.You can share the axis of subplots by setting
sharex=True
orsharey=True
.To share the range simply specify the limits of either axis:
plt.xlim(0,4)
andplt.ylim(-100,700)
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1,2, sharex=True, sharey=True)
dummy_One.hist(ax=axes[0], orientation="horizontal")
dummy_Two.hist(ax=axes[1], orientation="horizontal")
plt.ylim(-100,700)
plt.xlim(0,4)
plt.show()
Answered By - D. Rooij
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.