2015-09-20 5 views
5

मैं x- और y-axis लेबल्स के साथ-साथ पांडस के माध्यम से बनाए गए तीन-पैनल हिस्टोग्राम पर एक शीर्षक डालने का प्रयास कर रहा हूं, लेकिन इसे सही तरीके से नहीं लग रहा है। एकमात्र परिणाम जो मैंने शीर्षक में प्राप्त किया है और तीन ग्राफ़ के आखिरी पर एक्स-अक्ष लेबल है। मुझे एक समग्र शीर्षक, xlabel और ylabel चाहिए। कोड जो साजिश बनाता है नीचे है। कोई सुझाव?पांडस हिस्टोग्राम लेबल और शीर्षक

df1.hist(column='human_den',by='region',sharex=True,sharey=True,layout=(1,3)) 

उत्तर

5

स्वीकार किए जाते हैं जवाब here से साथ के बाद, subplots का उपयोग Figure और axis वस्तुओं उदाहरणों बनाने के लिए।

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 

# random data 
df1 = pd.DataFrame(columns=['human_den','region']) 
df1['human_den'] = np.random.rand(100) 
df1['region'] = np.random.choice(['Northeast', 'South', 'Midwest'], size=100) 

# set up figure & axes 
fig, axes = plt.subplots(nrows=1, ncols=3, sharex=True, sharey=True) 

# drop sharex, sharey, layout & add ax=axes 
df1.hist(column='human_den',by='region', ax=axes) 

# set title and axis labels 
plt.suptitle('Your Title Here', x=0.5, y=1.05, ha='center', fontsize='xx-large') 
fig.text(0.5, 0.04, 'common X', ha='center') 
fig.text(0.04, 0.5, 'common Y', va='center', rotation='vertical') 

सूचना, कीवर्ड तर्क sharex, sharey, और layoutdf1.hist() में निर्दिष्ट नहीं किए जाते, sharex, sharey, nrows और plt.subplots में ncols की स्थापना समान प्रभाव को प्राप्त करने के पक्ष में। महत्वपूर्ण तत्व df.hist() के कीवर्ड तर्क, ax को पहले प्रारंभिक axes ऑब्जेक्ट को असाइन कर रहा है। शीर्षक suptitle के साथ सेट किया जा सकता है।

Shared x and shared y common label

संबंधित मुद्दे