The relationship between dpi and shape size

I created a shape using matplotlib, but I understood the axis of the graph, and the drawn line decreased. enter image description here

After reading this earlier discussion thread , it explains how to set the shape size.

fig, ax = plt.subplots()

fig.set_size_inches(3, 1.5)

plt.savefig(file.jpeg, edgecolor='black', dpi=400, facecolor='black', transparent=True)

With the code above (other configurations removed for brevity), I get the resulting image file with the 1200 X 600desired size (should we say resolution too?) And the desired file size.

The projected image scales in an unusual way, such as annotations. I can set the size of the marks on the axis, but the figure still does not look proportional to the scale, since the lower and right spikes are still large, and this is also a drawn line.

, , , ?

+1
1

(figsize) . , ( ) . (6.4, 4.8) matplotlib 2. , .

(dpi) , . dpi matplotlib 100. figsize=(w,h)

px, py = w*dpi, h*dpi  # pixels
# e.g.
# 6.4 inches * 100 dpi = 640 pixels

, , . (1200,600) dpi, .

figsize=(15,7.5), dpi= 80
figsize=(12,6)  , dpi=100
figsize=( 8,4)  , dpi=150
figsize=( 6,3)  , dpi=200
etc.

, ? . , , , , , .
Matplotlib (ppi) 72. 1 1./72. . 12 12./72. .

, , , - . , , . , , , .

, dpi . 72 dpi 1 . 144 dpi 2 . , dpi . .

dpi . dpi . .

enter image description here

:

import matplotlib.pyplot as plt
%matplotlib inline

def plot(fs,dpi):
    fig, ax=plt.subplots(figsize=fs, dpi=dpi)
    ax.set_title("Figsize: {}, dpi: {}".format(fs,dpi))
    ax.plot([2,4,1,5], label="Label")
    ax.legend()

figsize=(2,2)
for i in range(1,4):
    plot(figsize, i*72)

dpi=72
for i in [2,4,6]:
    plot((i,i), dpi)
+2

Source: https://habr.com/ru/post/1679981/


All Articles