Reputation: 61
How can I manage the tick for this horizontal histogram?
My code:
d1=pd.read_csv('Gold1.Dat')
d1.dropna(subset=['WF (mV)'],how='any', inplace=True)
binwidth=5
m_n=np.floor(min(d1['WF (mV)'])/binwidth)*binwidth
m_x=np.floor(max(d1['WF (mV)'])/binwidth)*binwidth+binwidth
print(m_n)
print(m_x)
print(m_x-m_n)
binnum=int((m_x-m_n)/binwidth)
print(binnum)
a,b,c=plt.hist(d1['WF (mV)'],bins=binnum,range=(m_n,m_x),edgecolor='k',orientation='horizontal')
plt.xticks(b,rotation=45)
plt.tight_layout()
plt.savefig('vertical histogram')
Upvotes: 0
Views: 89
Reputation: 917
You should be using plt.yticks instead: matplotlib.pyplot.yticks(ticks=None, labels=None, **kwargs) to get or set the current tick locations and labels of the y-axis.
As a reference take a look at the following code that compares vertical vs horizontal histogram plotting:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
rating = pd.read_csv('Book1.csv')
plt.subplot(1, 2, 1)
bins_age = np.arange(18, rating['Age'].max() + 2, 2)
plt.hist(rating['Age'], bins=bins_age, orientation='horizontal')
ticks_age = np.arange(18, rating['Age'].max() + 10, 10)
labels_age = ticks_age**2
plt.yticks(ticks=ticks_age, labels=labels_age)
plt.subplot(1, 2, 2)
bins_age = np.arange(18, rating['Age'].max() + 2, 2)
plt.hist(rating['Age'], bins=bins_age)
plt.show()
Output:
Upvotes: 0