I plot a picture as follow:
I want save it lossless, and I use
to get a vector picture, but when I zoom in the picture the object can not vis correctly.
This is the picture I saved:
This is the plot by matplotlib, I want the effect like this:
How could I get that picture?
Can you simplify this example and provide minimal code?
I do not fully understand what is wrong with the later pictures, but I supect it has to do with what things are sized in data units and which things are sized in “screen units”.
Just like the follow example:
import matplotlib.pyplot as plt
import numpy as np
num = 100
x = np.linspace(0, 10, 100)
y = np.linspace(0, 10, 100)
plt.plot(x, y, "b", marker=".", markersize=10)
The picture I saved could not zoom in to watch the details(styles), but that’s worked in matplot’s backend.
By “Matplotlib’s backend”, I assume you mean when you save it as a png which is a raster backend. Thus, when you save the figure it is a fixed number of pixels and all of features are fixed size (in pixels) based on their size (which things like line width are set in physical units (pts (which are 1/72th of an inch for…long historical reasons going back to printing press)) and the dpi you saved the figure . When you “zoom in” the viewer program is effectively making the pixel bigger and up-scaling.
In contrast in a vector backend the line width is encoded in the file in the physical units. When you “zoom in” the svg viewer program will re-render and draw the line at the same physical width.
I apologize if I have misunderstood what you are asking.
Thanks for your answer firstly! I knew the difference between the svg format and the png format.
Maybe my poor english skill make the question a little bit confused…Let me re-ask again. Like the sample code I uploaded before, I plot a line and save it with svg format. But when I “zoom in” in the “test.svg”, I do not get the correct visualization.
This is “test.svg” I saved, called first picture.
This is used plt.show() to watched, called second picture.
In the origin window size, these two pictures is the same like the first picture. But when I maximized the window the second picture gives more details(small dot and correct clearance between each dot), and the first picture is nothing to change.
I want save a picture like the second picture can correctly resized pixels when I zoom in/out. Is there a method?
Also notice how in the second picture the text is much smaller, this is because from Matplotlib’s point of view the second one is much bigger in inches, hence everything that is sized in physical units (the marker size, the text, the line width) will be a smaller fraction of the total size of the figure. Thus if you take resize the total images to be about the same size, everything will be “smaller” in the bigger (in inches) figure.
If those are screen shots from your computer I think I am wrong about what your SVG viewer is doing when you zoom in it (rather than changing the size, it is effecitvely changing the DPI to be bigger and then showing you on a screen with lower DPI, but still mapping the pixels 1:1).
If you were to view these both at their correct relative sizes (easiest way to check this is that the text is the same size) the top one would be much smaller than the bottom one.
I think what you want to do is set the figure size (in inches) to be larger (either pass
plt.figure(figsize=(10, 12)) or use
fig.set_figsize_inches()) to be larger. This is effectively what setting the window to full-size does (when you resize the window we call
set_figsize_inches behind the scenes for you).
These things are hard to communicate between native English speakers.
Set the figsize can not solve my problem T T
Ok, maybe the idea can not achieve now.