Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. import matplotlib
  2. matplotlib.rc('xtick', labelsize=20)
  3. matplotlib.rc('ytick', labelsize=20)
  4.  
  5. font = {'family' : 'normal',
  6. 'weight' : 'bold',
  7. 'size' : 22}
  8.  
  9. matplotlib.rc('font', **font)
  10.  
  11. matplotlib.rcParams.update({'font.size': 22})
  12.  
  13. matplotlib.rcParams.update({'font.size': 22})
  14.  
  15. import matplotlib.pyplot as plt
  16.  
  17. ax = plt.subplot(111, xlabel='x', ylabel='y', title='title')
  18. for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] +
  19. ax.get_xticklabels() + ax.get_yticklabels()):
  20. item.set_fontsize(20)
  21.  
  22. import numpy as np
  23. import matplotlib.pyplot as plt
  24. import matplotlib.font_manager as font_manager
  25.  
  26. # Set the font dictionaries (for plot title and axis titles)
  27. title_font = {'fontname':'Arial', 'size':'16', 'color':'black', 'weight':'normal',
  28. 'verticalalignment':'bottom'} # Bottom vertical alignment for more space
  29. axis_font = {'fontname':'Arial', 'size':'14'}
  30.  
  31. # Set the font properties (for use in legend)
  32. font_path = 'C:WindowsFontsArial.ttf'
  33. font_prop = font_manager.FontProperties(fname=font_path, size=14)
  34.  
  35. ax = plt.subplot() # Defines ax variable by creating an empty plot
  36.  
  37. # Set the tick labels font
  38. for label in (ax.get_xticklabels() + ax.get_yticklabels()):
  39. label.set_fontname('Arial')
  40. label.set_fontsize(13)
  41.  
  42. x = np.linspace(0, 10)
  43. y = x + np.random.normal(x) # Just simulates some data
  44.  
  45. plt.plot(x, y, 'b+', label='Data points')
  46. plt.xlabel("x axis", **axis_font)
  47. plt.ylabel("y axis", **axis_font)
  48. plt.title("Misc graph", **title_font)
  49. plt.legend(loc='lower right', prop=font_prop, numpoints=1)
  50. plt.text(0, 0, "Misc text", **title_font)
  51. plt.show()
  52.  
  53. import numpy as np
  54. import matplotlib.pyplot as plt
  55. import matplotlib.font_manager as font_manager
  56. import matplotlib.ticker
  57. # Workaround for Matplotlib 2.0.0 log axes bug https://github.com/matplotlib/matplotlib/issues/8017 :
  58. matplotlib.ticker._mathdefault = lambda x: '\mathdefault{%s}'%x
  59.  
  60. # Set the font properties (can use more variables for more fonts)
  61. font_path = 'C:WindowsFontsAGaramondPro-Regular.otf'
  62. font_prop = font_manager.FontProperties(fname=font_path, size=14)
  63.  
  64. ax = plt.subplot() # Defines ax variable by creating an empty plot
  65.  
  66. # Define the data to be plotted
  67. x = np.linspace(0, 10)
  68. y = x + np.random.normal(x)
  69. plt.plot(x, y, 'b+', label='Data points')
  70.  
  71. for label in (ax.get_xticklabels() + ax.get_yticklabels()):
  72. label.set_fontproperties(font_prop)
  73. label.set_fontsize(13) # Size here overrides font_prop
  74.  
  75. plt.title("Exponentially decaying oscillations", fontproperties=font_prop,
  76. size=16, verticalalignment='bottom') # Size here overrides font_prop
  77. plt.xlabel("Time", fontproperties=font_prop)
  78. plt.ylabel("Amplitude", fontproperties=font_prop)
  79. plt.text(0, 0, "Misc text", fontproperties=font_prop)
  80.  
  81. lgd = plt.legend(loc='lower right', prop=font_prop) # NB different 'prop' argument for legend
  82. lgd.set_title("Legend", prop=font_prop)
  83.  
  84. plt.show()
  85.  
  86. import matplotlib.pyplot as plt
  87.  
  88. SMALL_SIZE = 8
  89. MEDIUM_SIZE = 10
  90. BIGGER_SIZE = 12
  91.  
  92. plt.rc('font', size=SMALL_SIZE) # controls default text sizes
  93. plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title
  94. plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels
  95. plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels
  96. plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels
  97. plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize
  98. plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title
  99.  
  100. import matplotlib
  101.  
  102. SMALL_SIZE = 8
  103. matplotlib.rc('font', size=SMALL_SIZE)
  104. matplotlib.rc('axes', titlesize=SMALL_SIZE)
  105.  
  106. # and so on ...
  107.  
  108. import matplotlib.pyplot as plt
  109. import numpy as np
  110. [enter image description here][1]fig = plt.figure(figsize=(4,3))
  111. ax = fig.add_subplot(111)
  112. x = np.linspace(0,6.28,21)
  113. ax.plot(x, np.sin(x), '-^', label="1 Hz")
  114. ax.set_title("Oscillator Output")
  115. ax.set_xlabel("Time (s)")
  116. ax.set_ylabel("Output (V)")
  117. ax.grid(True)
  118. ax.legend(loc=1)
  119. fig.savefig('Basic.png', dpi=300)
  120.  
  121. import matplotlib.pyplot as plt
  122. import matplotlib.font_manager as fm
  123.  
  124. fontPath = "/usr/share/fonts/abc.ttf"
  125. font = fm.FontProperties(fname=fontPath, size=10)
  126. font2 = fm.FontProperties(fname=fontPath, size=24)
  127.  
  128. fig = plt.figure(figsize=(32, 24))
  129. fig.text(0.5, 0.93, "This is my Title", horizontalalignment='center', fontproperties=font2)
  130.  
  131. plot = fig.add_subplot(1, 1, 1)
  132.  
  133. plot.xaxis.get_label().set_fontproperties(font)
  134. plot.yaxis.get_label().set_fontproperties(font)
  135. plot.legend(loc='upper right', prop=font)
  136.  
  137. for label in (plot.get_xticklabels() + plot.get_yticklabels()):
  138. label.set_fontproperties(font)
  139.  
  140. import matplotlib.pyplot as plt
  141. plt.figure(figsize=(4,3))
  142. plt.savefig('Basic.pdf', bbox_inches='tight')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement