2
Y 축 (로그 눈금)에서 0-10 범위가 다른 범위보다 작은 이유는 무엇입니까? 10-100, 100-1000 등). x 눈금 표시와 값의 위치를 조정하는 방법이 있습니까? 나는 작은 값을 분명히 보여주고 싶다. 이 작업을 수행하는 Python (Pandas 또는 matplotlib)의 막대 그래프에서 로그 축 눈금 위치 (10 개)를 이동하는 방법
word_freqs, words
([[7637.78430956, 1938.76578683, 208.902929772, 40.3146004823,
120.943801447],
[6.99469414131, 46.9678505732, 51.2011611144, 0, 93.9478658318],
[3773.94093782, 188.697046891, 943.485234456, 849.13671101, 377.394093782]],
['energiestadt','energiepolitik','energieversorgung','energietag',
'energiestrategie'])
내 스크립트 Reference입니다 : y 축의
import pandas as pd
import matplotlib.pyplot as plt
raw_data = {'Words': words,
'energie_energiestadt': word_freqs[0],
'energie_march2017': word_freqs[1],
'energie_smartcity': word_freqs[2]}
df = pd.DataFrame(raw_data, columns = ['Words', 'energie_energiestadt',
'energie_march2017', 'energie_smartcity'])
df
# Setting the positions and width for the bars
pos = list(range(len(df['energie_energiestadt'])))
width = 0.25
# Plotting the bars
fig, ax = plt.subplots(figsize=(10,5))
# Create a bar with energie_energiestadt data,
# in position pos,
plt.bar(pos,
#using df['energie_energiestadt'] data,
df['energie_energiestadt'],
# of width
width,
# with alpha 0.5
alpha=0.5,
# with color
color='#EE3224',
# with label the first value in Words
label=df['Words'][0])
# Create a bar with energie_march2017 data,
# in position pos + some width buffer,
plt.bar([p + width for p in pos],
#using df['energie_march2017'] data,
df['energie_march2017'],
# of width
width,
# with alpha 0.5
alpha=0.5,
# with color
color='#F78F2E',
# with label the second value in Words
label=df['Words'][1])
# Create a bar with energie_smartcity data,
# in position pos + some width buffer,
plt.bar([p + width*2 for p in pos],
#using df['energie_smartcity'] data,
df['energie_smartcity'],
# of width
width,
# with alpha 0.5
alpha=0.5,
# with color
color='#FFC222',
# with label the third value in Words
label=df['Words'][2], log=1)
# Set the y axis label
ax.set_ylabel('Frequency')
# Set the chart's title
ax.set_title('Frequency of words in different texts')
# Set the position of the x ticks
ax.set_xticks([p + 1.5 * width for p in pos])
# Set the labels for the x ticks
ax.set_xticklabels(df['Words'])
# Setting the x-axis and y-axis limits
plt.xlim(min(pos)-width, max(pos)+width*4)
plt.ylim([0, max(df['energie_energiestadt'] + df['energie_march2017'] +
df['energie_smartcity'])])
# Adding the legend and showing the plot
plt.legend(['energie energiestadt', 'energie march2017', 'energie
smartcity'], loc='upper right')
plt.grid()
plt.show()