-1

I am trying to plot a bar graph using matplotlib pyplot, but figure is really strange.enter image description hereAxis are too large as highlighted by yellow color, x and y labels are out of the screen. Also I would like to remove lines highlighted in red. Here is the code.

import matplotlib.pyplot as plt
plt.figure(figsize=(2, 1))
plt.bar(index, auc_score_per_class)    # index and auc.. are arrays
plt.xlabel('Attributes', fontsize=0.5)
plt.ylabel('Score', fontsize=1)
plt.xticks(index, labels, fontsize=0.5, rotation=90)
plt.savefig('auc.jpg', format='jpg', dpi=1024)

Kindly let me know, 1. how to decrease the size of axis lines and scale highlighted in yellow, 2. remove lines highlighted in red and 3. Avoid x and y lables from vanishing out of figure.

Thanks.

adeelz92
  • 469
  • 1
  • 5
  • 17
  • 1
    Creating a really small figure ((2,1) inches) and using a really huge dpi inevitably leads to problems. You would achieve the same figure size (in pixels) with `figsize = (16,8)` and `dpi=128`, in which case the lines should have the normal size. – ImportanceOfBeingErnest Jul 29 '18 at 14:46
  • Read up on spines to get rid of the lines highlighted in red: https://matplotlib.org/api/spines_api.html You can do something like this: ax.spines['right'].set_color("none") – SamrajM Jul 29 '18 at 14:48

1 Answers1

0
import matplotlib as mpl
mpl.rcParams['axes.linewidth'] = 0.4 # or any other thickness you want

The second question is already answered here: How can I remove the top and right axis in matplotlib?

For the size of axis values (scale):

ax = fig.add_subplot(111)
for tick in ax.xaxis.get_major_ticks():
    tick.label.set_fontsize(8)
for tick in ax.yaxis.get_major_ticks():
    tick.label.set_fontsize(8)
Sheldore
  • 37,862
  • 7
  • 57
  • 71