[X-Stackoverflow] Sequence logos using matplotlib: transforming xticks

I asked this question on stackoverflow and thought it would make sense to
post it here as well:
http://stackoverflow.com/questions/42615527/matplotlib-scaled-text-and-xticks

Thanks,
Saket
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170305/e95a698f/attachment.html>

Hello,

I use python(3.6)+numpy+matplotlib(2.0) (Anaconda distribution under
Win7) to draw simple figures and I meet the following problem. All the
figures that I plot come out the same size (432x288 px). This is OK for
simple curves but leads to obscure plots in more complicated cases.
I notice that all figures in the pyplot tutorial have size 550x450 as
they do also in the Matplotlib examples, while many figures in the
gallery are 165x135.

How canI force the size of a picture in order to display it full screen
or to cover most of anA4 sheet of paper ?

Thank you for your help
JP Grivet

···

---
L'absence de virus dans ce courrier ?lectronique a ?t? v?rifi?e par le logiciel antivirus Avast.
https://www.avast.com/antivirus

Hello Jean-Philippe,

you can use the `figsize` keyword argument when creating a figure to set
its size in inches (1 in = 2.54 cm). You can also set the DPI value
directly with the `dpi` argument. Or you can wait until saving the
figure: the keyword argument is the same.

For example


import matplotlib.pyplot as plt

# Set the dimensions that you want in inches,
# here let's say a quarter of a A4 sheet.
a4_sheet = (21.0, 29.7)  # in cm
my_size = [0.5*val/2.54 for val in a4_sheet]  # converted in inches

fig, ax = plt.subplots(figsize=my_size)  # one could add 'dpi=300'

ax.plot([0, 1, 2], [1, 2, 0])  # dummy plot

# Saving with a specific dot-per-inch (dpi) value, here 300
# Given my_size, the final picture should be ~ 1240x1754
fig.savefig('my_figure_in_300_dpi.png', dpi=300)

You may find more details in the online documentation:

···

-
[pyplot.figure](http://matplotlib.org/api/pyplot_api.html?highlight=figure#matplotlib.pyplot.figure)
-
[pyplot.savefig](http://matplotlib.org/api/pyplot_api.html?highlight=savefig#matplotlib.pyplot.savefig)

I hope this helps.

Regards

Adrien

PS: the figure size that you report is a bit surprising. The 2.0
defaults are expected to produce 640?480 pixel-pictures (if I am not wrong).

On 08/03/2017 15:19, Jean-Philippe Grivet wrote:

Hello,

I use python(3.6)+numpy+matplotlib(2.0) (Anaconda distribution under
Win7) to draw simple figures and I meet the following problem. All the
figures that I plot come out the same size (432x288 px). This is OK for
simple curves but leads to obscure plots in more complicated cases.
I notice that all figures in the pyplot tutorial have size 550x450 as
they do also in the Matplotlib examples, while many figures in the
gallery are 165x135.

How canI force the size of a picture in order to display it full screen
or to cover most of anA4 sheet of paper ?

Thank you for your help
JP Grivet

---
L'absence de virus dans ce courrier ?lectronique a ?t? v?rifi?e par le
logiciel antivirus Avast.
https://www.avast.com/antivirus

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

The figures in the gallery and documentation might also be automatically
cropped to eliminate white space.

···

On Wed, Mar 8, 2017 at 10:15 AM, vincent.adrien at gmail.com < vincent.adrien at gmail.com> wrote:

Hello Jean-Philippe,

you can use the `figsize` keyword argument when creating a figure to set
its size in inches (1 in = 2.54 cm). You can also set the DPI value
directly with the `dpi` argument. Or you can wait until saving the
figure: the keyword argument is the same.

For example


import matplotlib.pyplot as plt

# Set the dimensions that you want in inches,
# here let's say a quarter of a A4 sheet.
a4_sheet = (21.0, 29.7)  # in cm
my_size = [0.5*val/2.54 for val in a4_sheet]  # converted in inches

fig, ax = plt.subplots(figsize=my_size)  # one could add 'dpi=300'

ax.plot([0, 1, 2], [1, 2, 0])  # dummy plot

# Saving with a specific dot-per-inch (dpi) value, here 300
# Given my_size, the final picture should be ~ 1240x1754
fig.savefig('my_figure_in_300_dpi.png', dpi=300)

You may find more details in the online documentation:
-
[pyplot.figure](http://matplotlib.org/api/pyplot_api.
html?highlight=figure#matplotlib.pyplot.figure)
-
[pyplot.savefig](http://matplotlib.org/api/pyplot_api.
html?highlight=savefig#matplotlib.pyplot.savefig)

I hope this helps.

Regards

Adrien

PS: the figure size that you report is a bit surprising. The 2.0
defaults are expected to produce 640?480 pixel-pictures (if I am not
wrong).

On 08/03/2017 15:19, Jean-Philippe Grivet wrote:
> Hello,
>
> I use python(3.6)+numpy+matplotlib(2.0) (Anaconda distribution under
> Win7) to draw simple figures and I meet the following problem. All the
> figures that I plot come out the same size (432x288 px). This is OK for
> simple curves but leads to obscure plots in more complicated cases.
> I notice that all figures in the pyplot tutorial have size 550x450 as
> they do also in the Matplotlib examples, while many figures in the
> gallery are 165x135.
>
> How canI force the size of a picture in order to display it full screen
> or to cover most of anA4 sheet of paper ?
>
> Thank you for your help
> JP Grivet
>
>
> ---
> L'absence de virus dans ce courrier ?lectronique a ?t? v?rifi?e par le
> logiciel antivirus Avast.
> https://www.avast.com/antivirus
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170308/c5931666/attachment.html>