Learn Python

Learn Data Structure & Algorithm

Learn Numpy

Learn Pandas

Matplotlib Introduction

Matplotlib Bar Plot

Matplotlib Pie Chart

Matplotlib Hist Plot

Matplotlib Line Plot

Matplotlib Scatter Plot

Matplotlib Subplot

Matplotlib Save image

Learn Seaborn

Learn Statistics

Learn Math

Learn MATLAB

Learn Machine learning

Learn Github

Learn OpenCV

Learn Deep Learning

Learn MySQL

Learn MongoDB

Learn Web scraping

Learn Excel

Learn Power BI

Learn Tableau

Learn Docker

Learn Hadoop

How to save image & chart in matplotlib?

To save an image of charts write module_name. savefig("Here write image name as a string"). The image will save in the project's directory. Project directory means that place in pc where you save another file of that particular project. By default, you will get the image in png format.

Input
import matplotlib.pyplot as plt
value1=[40,45,67,78,90,2,2,33]
value2=[55,70,81,88,100,55,67,44]
plt.scatter(value1,value2,color="red")
plt.title("Histogram for practice")
plt.xlabel("x axis value")
plt.ylabel("y axis value")
plt.grid(color="red",linewidth=2,linestyle=":")
plt.legend(["value1","value2"])
plt.savefig("scatter plot")
plt.show()

How to adjust dpi of the image?

Here dpi means dot(pixel) per inch. To set dpi use the dpi parameter and pass integer value. By default, the dpi value is 100. You can increase or decrease the resolution of the image by increasing or decreasing the dpi value.

Input
import matplotlib.pyplot as plt
value1=[40,45,67,78,90,2,2,33]
value2=[55,70,81,88,100,55,67,44]
plt.scatter(value1,value2,color="red")
plt.title("Histogram for practice")
plt.xlabel("x axis value")
plt.ylabel("y axis value")
plt.grid(color="red",linewidth=2,linestyle=":")
plt.legend(["value1","value2"])
plt.savefig("scatter plot with default dpi")
plt.savefig("scatter plot with 50 dpi",dpi=50)
plt.savefig("scatter plot with 200 dpi",dpi=200)
plt.savefig("scatter plot with 1000 dpi",dpi=1000)
plt.show()

CodersAim is created for learning and training a self learner to become a professional from beginner. While using CodersAim, you agree to have read and accepted our terms of use, privacy policy, Contact Us

© Copyright All rights reserved www.CodersAim.com. Developed by CodersAim.