[Matplotlib-users] size of the picture

vincent.adrien at gmail.com vincent.adrien at gmail.com
Thu Nov 30 02:42:57 EST 2017


Hi Vincent,

Here is a small snippet of code on the very same idea that Jody already 
suggested, but this time with examples of texts, labels, etc. :).

```python
import matplotlib.pyplot as plt
plt.ion()  # if you do not want displaying of figures to be blocking

# Default cosmetick tweaks. Note than one could also define the default
# figure size, as well as the weight of the fonts, etc.
plt.style.use(["default"])  # reset: better safe than sorry
plt.rcParams["font.size"] = 10  # in points
plt.rcParams["axes.labelsize"] = 10  # in points
plt.rcParams["axes.titlesize"] = 10  # in points

# This is what you may looking for. Knowing the size of the figures
# that you produce, you should be able to ask LaTeX to use the exact
# same physical dimensions :).
width, height = (4, 3)  # in inches (NB: 72 points per inch)
fig, ax = plt.subplots(figsize=(width, height))

# Dummy data (I was too lazy to import Numpy...)
x = [-1, 0, 1, 2]
y = [val**2 for val in x]
ax.plot(x, y, label="A line")

# Exercise most of the possible text of a plot
ax.set_xlabel("$x$")
ax.set_ylabel("$y = x^2$")
ax.set_title("A simple figure")
ax.legend()

fig.tight_layout()  # to nicely fit the subplot(s) in the figure

# Record the figure in the format that you prefer
fig.savefig("my_figure.png", dpi=600)
fig.savefig("my_figure.pdf")
```

If you have more general questions about the usage of Matplotlib, you 
may also find some useful informations in 
[here](https://matplotlib.org/tutorials/index.html)

Best regards,
Adrien

On 11/29/2017 10:40 PM, vincent_mathoscope wrote:
> thank you Jody
> i tried quickly your code before going to work
> this code :
> 
> just gave an empty picture with some graduations on the axes that were not
> coded in my picture
> if you have a cuple of seconds to explain a bit longer that will be useful
> for me
> otherwise i take time to look at it this evening
> 
> 
> 
> -----
>          ––––––––––––––––––––––––––
>                    Vincent Douce
>                 :=: Mathoscope :=:
>               http://mathoscope.xyz
>                   06°13°11°07°26
>            Bagnères de Bigorre 65200
> --
> Sent from: http://matplotlib.1069221.n5.nabble.com/matplotlib-users-f3.html
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
> 



More information about the Matplotlib-users mailing list