2

In python3 and pandas I have this dataframe:

gastos_anuais.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 5 entries, 0 to 4
Data columns (total 2 columns):
ano           5 non-null int64
valor_pago    5 non-null float64
dtypes: float64(1), int64(1)
memory usage: 280.0 bytes

gastos_anuais.reset_index()
    index   ano     valor_pago
0   0   2014    13,082,008,854.37
1   3   2017    9,412,069,205.73
2   2   2016    7,617,420,559.22
3   1   2015    7,470,391,492.24
4   4   2018    7,099,199,179.11

I did a pointplot chart:

import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline

sns.pointplot(x='ano', y='valor_pago', data=gastos_anuais)

plt.xticks(rotation=65)
plt.grid(True, linestyle="--")
plt.title("Gastos Destinados pelo Governo Federal (2014-2018)\n")
plt.xlabel("Anos")
plt.ylabel("Em bilhões de R$")
plt.show()

It worked. But I would like to:

  • Increase the size of the chart that appears on the screen

  • Can save image format, .jpeg file for example

  • And I do not understand why below the title of the graph appears '1e10'

Please, does anyone know how I can do it?

Reinaldo Chaves
  • 965
  • 4
  • 16
  • 43
  • Possible duplicate of [How do you change the size of figures drawn with matplotlib?](https://stackoverflow.com/questions/332289/how-do-you-change-the-size-of-figures-drawn-with-matplotlib) – Diziet Asahi Nov 22 '18 at 20:46

1 Answers1

5

Increase the size of the chart that appears on the screen

Add sns.set(rc={'figure.figsize':(w, h)}) before plotting. For example:

sns.set(rc={'figure.figsize':(20, 5)})

Save as jpg

Keep a reference to the plot, get the figure and save it:

p = sns.pointplot(x='ano', y='valor_pago', data=gastos_anuais)

plt.xticks(rotation=65)
#...
# All your editions with `plt`
#...

fig = p.get_figure()
fig.savefig("gastos_anuais.jpg")

What is the 1e10 in the corner?

It is the scale. This means that the values shown in the y axis should be multiplied by 10^10 to recover the actual values of the data.

If you want to remove it, you can use:

plt.ticklabel_format(style='plain', axis='y')

But you will need to do something with the values since they distort the image.

dataista
  • 3,187
  • 1
  • 16
  • 23