अपडेट: उत्तर के निचले हिस्से को थोड़ा बेहतर तरीके से करने के लिए इसे देखें।
# 2 अद्यतन करें: मुझे पता है कि किंवदंती शीर्षक फोंट बदल रहा है।
अपडेट # 3: Matplotlib 2.0.0 में एक बग है है जो डिफ़ॉल्ट फ़ॉन्ट को वापस करने के लिए लॉगरिदमिक कुल्हाड़ियों के लिए टिक लेबल का कारण बन रहा है। 2.0.1 में तय किया जाना चाहिए, लेकिन मैंने उत्तर के दूसरे भाग में वर्कअराउंड को शामिल किया है।
यह उत्तर किसी के लिए भी है, जिसमें किंवदंती सहित सभी फोंट को बदलने की कोशिश की गई है, और प्रत्येक चीज़ के लिए अलग-अलग फोंट और आकारों का उपयोग करने की कोशिश करने वाले किसी भी व्यक्ति के लिए है। यह आरसी (जो मेरे लिए काम नहीं करता है) का उपयोग नहीं करता है। यह बल्कि बोझिल है, लेकिन मैं व्यक्तिगत रूप से किसी अन्य विधि के साथ पकड़ में नहीं आ सका। यह मूल रूप से एसओ पर अन्य जवाबों के साथ यहाँ ryggyr के उत्तर को जोड़ती है।
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
# Set the font dictionaries (for plot title and axis titles)
title_font = {'fontname':'Arial', 'size':'16', 'color':'black', 'weight':'normal',
'verticalalignment':'bottom'} # Bottom vertical alignment for more space
axis_font = {'fontname':'Arial', 'size':'14'}
# Set the font properties (for use in legend)
font_path = 'C:\Windows\Fonts\Arial.ttf'
font_prop = font_manager.FontProperties(fname=font_path, size=14)
ax = plt.subplot() # Defines ax variable by creating an empty plot
# Set the tick labels font
for label in (ax.get_xticklabels() + ax.get_yticklabels()):
label.set_fontname('Arial')
label.set_fontsize(13)
x = np.linspace(0, 10)
y = x + np.random.normal(x) # Just simulates some data
plt.plot(x, y, 'b+', label='Data points')
plt.xlabel("x axis", **axis_font)
plt.ylabel("y axis", **axis_font)
plt.title("Misc graph", **title_font)
plt.legend(loc='lower right', prop=font_prop, numpoints=1)
plt.text(0, 0, "Misc text", **title_font)
plt.show()
इस पद्धति का लाभ यह है कि, कई फॉन्ट शब्दकोश होने से, आप विभिन्न शीर्षकों के लिए अलग-अलग फ़ॉन्ट / आकार / वजन / रंग चुन सकते हैं, टिक लेबल के लिए फ़ॉन्ट का चयन कर सकते हैं, और सभी स्वतंत्र रूप से, किंवदंती के लिए फ़ॉन्ट चुन सकते हैं।
अपडेट करें:
मैंने फॉन्ट डिक्शनरी के साथ थोड़ा अलग, कम क्लॉटेड अप्रोच काम किया है, और आपके सिस्टम पर किसी भी फॉन्ट को, यहां तक कि फॉंट फॉन्ट को भी अनुमति देता है। प्रत्येक चीज़ के लिए अलग-अलग फोंट रखने के लिए, बस अधिक font_path
और font_prop
वैरिएबल लिखें ।
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
import matplotlib.ticker
# Workaround for Matplotlib 2.0.0 log axes bug https://github.com/matplotlib/matplotlib/issues/8017 :
matplotlib.ticker._mathdefault = lambda x: '\\mathdefault{%s}'%x
# Set the font properties (can use more variables for more fonts)
font_path = 'C:\Windows\Fonts\AGaramondPro-Regular.otf'
font_prop = font_manager.FontProperties(fname=font_path, size=14)
ax = plt.subplot() # Defines ax variable by creating an empty plot
# Define the data to be plotted
x = np.linspace(0, 10)
y = x + np.random.normal(x)
plt.plot(x, y, 'b+', label='Data points')
for label in (ax.get_xticklabels() + ax.get_yticklabels()):
label.set_fontproperties(font_prop)
label.set_fontsize(13) # Size here overrides font_prop
plt.title("Exponentially decaying oscillations", fontproperties=font_prop,
size=16, verticalalignment='bottom') # Size here overrides font_prop
plt.xlabel("Time", fontproperties=font_prop)
plt.ylabel("Amplitude", fontproperties=font_prop)
plt.text(0, 0, "Misc text", fontproperties=font_prop)
lgd = plt.legend(loc='lower right', prop=font_prop) # NB different 'prop' argument for legend
lgd.set_title("Legend", prop=font_prop)
plt.show()
उम्मीद है कि यह एक व्यापक जवाब है