In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use Python data visualization JupyterNotebook drawing to generate high-definition pictures, the editor thinks it is very practical, so I want to share it with you. I hope you can get something after reading this article. Let's take a look at it with the editor.
Recently, a little friend asked a question: how to be more "high-definition" when drawing with Matplotlib in jupyter notebook?
To take a small example, use Matplotlib to draw polar coordinates:
Import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%matplotlib inline s = pd.Series (np.arange (20)) fig = plt.figure (figsize= (8,4)) ax = plt.subplot (111111projection='polar') ax.plot (s, linestyle='--', marker='.', lw=3) plt.savefig ("temp.png")
Open the temp.png saved to the current working directory, and after zooming in, you will find that the pixel is a little bit dregs.
Some of my friends may say, then I'll just change the pixel size of the image.
Yes, but remember to change all the pixel sizes at the same time, not just the image size, otherwise it will be like the following.
We can add some parameters when saving the image.
For example, dpi is the resolution, dots per inch.
S = pd.Series (np.arange (20)) fig = plt.figure (figsize= (8,4)) ax = plt.subplot (111111projection='polar') ax.plot (s, linestyle='--', marker='.', lw=3) plt.savefig ("temp_1.png", dpi=500, bbox_inches='tight')
Another parameter, bbox_inches: only a given part of the graph will be saved. Set to "tight" to match the saved drawing properly.
The resulting image is high-definition enough.
There is another way to make the image high-definition.
I have previously introduced some magic commands, such as% matplotlib inline can be used directly in the Ipython compiler, the function is to inline drawing, and can omit plt.show () this step.
We can add another line of configuration to allow Matplotlib to output high-definition vector graphics on top of Jupyter Notebook.
% config InlineBackend.figure_format = 'svg'
The format of the output is svg, so the browser can render the vector image.
Change the save format and you get a high-definition vector picture.
The second method uses magic commands in Jupyter notebook to set the resolution at which the image is displayed.
The same parameter settings include:
% config InlineBackend.figure_format = "png"% config InlineBackend.figure_format = "svg"% config InlineBackend.figure_format = "retina"
On a higher resolution screen, such as a Retina display, the default image in Jupyter Notebook may appear blurred.
You can use% config InlineBackend.figure_format = "retina" after% matplotlib inline
To render a higher resolution image.
The above is how to use Python data visualization JupyterNotebook drawing to generate high-definition pictures, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.