0

in below simple matlotlib plot I want set the Helvertica font for text and axis label ad need to control the width of the axis, axis values. Additionally i need to write axis labels little bit differently like 'time' in both the axis will be just below right corner of INSTITUTE and COMPANY respectively.

import matplotlib.pyplot as plt
x=[1,2,3,4,5,6,7,8,9,10]
y=[2,3,4,5,4,6,8,10,23,10]
plt.xlabel('INSTITUTEtime')
plt.ylabel('COMPANYtime')
plt.plot(x,y)
plt.show()
Karthik
  • 2,181
  • 4
  • 10
  • 28

1 Answers1

0

Please check the snippet. I don't have Helvetica font. If you want that font you would want to download it and configure it in your matplotlibrc file. Please check Font Configuration for more details. graph

  • **xyconfig is used to extract elements from dictionary. Its called dictionary unpacking.
  • plt.text(10,-2,'time') here x-coordinate is 10 , y-coordinate is -2. As we know your x-axis limit is 10 so i gave x as 10 and i gave -2 because you wanted that text in bottom-right corner below (0,0) co-ordinate i.e negative y-axis
  • plt.text(-0.50,22,'time',rotation=90) here y-coordinate is 22 because your y-axis limit is 20 so to position it a little above ,i gave it 22 and x-coordinate is -0.5 because you want your text to be place behind your y-axis thus in negative y-axis.
  • rotation=90 is parameter to rotate your text. You can also use this in xticks and yticks
import matplotlib.pyplot as plt
x=[1,2,3,4,5,6,7,8,9,10]
y=[2,3,4,5,4,6,8,10,23,10]

xyconfig = {'fontname':'serif','size':12}
plt.xlabel('INSTITUTE',**xyconfig)
plt.ylabel('COMPANY',**xyconfig)
plt.xticks(fontname='serif',size=8)
plt.yticks(fontname='serif',size=8)
plt.plot(x,y)
plt.text(10,-2,'time')
plt.text(-0.50,22,'time',rotation=90)
plt.title("Institute vs Company Time")
plt.show()
Karthik
  • 2,181
  • 4
  • 10
  • 28