I wrote matplotlib

I tried to summarize the graphs that I often write with matplotlib

Semi-log graph

#Drawing the scale line
import matplotlib.pyplot as plt
import matplotlib

#Set figure
fig = plt.figure()

#Japanese setting
font = {'family' : ' IPAexGothic'}
matplotlib.rc('font', **font)


#Add Axes
ax = fig.add_subplot(111)

#Axis display settings
plt.xlabel("frequency")
plt.ylabel("Voltage")

#Set the axis range
ax.set_xlim(0.1, 1000)
ax.set_ylim(0, 1.04)

#x value y value setting
x = [0.1,0.2,0.4,0.7,1.0,2.0,4.0,7.0,10,20,40,70,100,200,400,700,1000]
y1 = [1, 1, 1, 0.980, 0.980, 0.980, 0.960, 0.920, 0.840, 0.680, 0.420, 0.280, 0.2, 0.120, 0.1, 0.080, 0.072]
y2 = [0.060, 0.060, 0.080, 0.100, 0.100, 0.180, 0.300, 0.460, 0.580, 0.800, 0.940, 0.980, 1.0, 1.02, 1.02, 1.02, 1.02]

plt.scatter(x, y1, s=30, c="r",label = "Whole")
plt.scatter(x, y2, s=30, c="b", label = "This this this",marker = "s")
#Semi-log graph settings
ax.set_xscale('log')


#Formatting the graph

plt.plot(x, y1, linestyle = "None", linewidth = 0)

 #Set auxiliary scale line on x-axis
ax.grid(which = "major", axis = "x", color = "black", alpha = 0.8,linestyle = "--", linewidth = 1)

#Set scale line on y-axis
ax.grid(which = "major", axis = "y", color = "black", alpha = 0.8,linestyle = "--", linewidth = 1)
plt.legend(loc='center right', borderaxespad=1)
plt.show()

Figure_1.png

Dot a dot and draw a straight line

#Drawing the scale line
import matplotlib.pyplot as plt
import matplotlib

#Set figure
fig = plt.figure()

#Japanese setting
font = {'family' : ' IPAexGothic'}
matplotlib.rc('font', **font)


#Add Axes
ax = fig.add_subplot(111)

#Axis display settings
plt.xlabel("Voltage")
plt.ylabel("Current")


#Set the axis range
ax.set_xlim(0,10.1)
ax.set_ylim(0, 4.3 )

#x value y value setting
x = [0,1,2,3,4,5,6,7,8,9,10]
y1 = [0,0.18, 0.35, 0.53, 0.71, 0.89, 1.07, 1.25, 1.43, 1.61, 1.78]
y2 = [0, 0.41, 0.83, 1.25, 1.67, 2.09, 2.51, 2.93, 3.35, 3.77, 4.19]

plt.scatter(x, y1, s=30, c="r",label = "Whole")
plt.scatter(x, y2, s=30, c="b", label = "This this this",marker = "s")


#Formatting the graph
#plt.plot(x, y1, marker="o", color = "red", linestyle = "-")
plt.plot(x, y1, marker = "o", color = "red", linestyle = "-")
plt.plot(x,y2, marker = "o", color = "blue", linestyle = "-")

 #Set auxiliary scale line on x-axis
ax.grid(which = "major", axis = "x", color = "black", alpha = 0.8,linestyle = "--", linewidth = 1)

#Set scale line on y-axis
ax.grid(which = "major", axis = "y", color = "black", alpha = 0.8,linestyle = "--", linewidth = 1)

plt.legend(loc='upper left', borderaxespad=1)
plt.show()

Figure_2.png

Dot and draw a parabola

#Drawing the scale line
import matplotlib.pyplot as plt
import matplotlib

#Set figure
fig = plt.figure()

#Japanese setting
font = {'family' : ' IPAexGothic'}
matplotlib.rc('font', **font)


#Add Axes
ax = fig.add_subplot(111)

#Axis display settings
plt.xlabel("Voltage")
plt.ylabel("Current")
plt.title("The title is here.")

#Set the axis range
#ax.set_xlim(0, 1.0)
#ax.set_ylim(0, 30)

#x value y value setting
x = [0,0.1,0.2,0.3,0.4,0.5,0.60,0.65,0.68,0.7,0.72,0.74,0.75,0.76,0.78,0.8]
y1 = [0,0,0,0,0,0,0.02,0.10,0.28,0.54,1.42,3.21,4.7,4.98,10.87,30.15]

len_x = len(x)
print(len_x)
len_y1 = len(y1)
print(len_y1)
#Formatting the graph
plt.plot(x, y1, marker="o", color = "red", linestyle = "-")

#Set auxiliary scale line on x-axis
ax.grid(which = "major", axis = "x", color = "blue", alpha = 0.8,
        linestyle = "--", linewidth = 1)

#Set scale line on y-axis
ax.grid(which = "major", axis = "y", color = "green", alpha = 0.8,
        linestyle = "--", linewidth = 1)
plt.show()

Figure_3.png

Corrected to make a curve when hitting a point

The following sites will be helpful. Computational physicist research memorandum http://keisanbutsuriya.hateblo.jp/entry/2015/12/24/172953

reference https://techacademy.jp/magazine/19316 https://qiita.com/sci_Haru/items/68bd9a05d99598d445b0 https://paper.hatenadiary.jp/entry/2017/05/02/152223

Thank you for reading to the end.

Recommended Posts

I wrote matplotlib
I tried using matplotlib
I wrote GP with numpy
I wrote python in Japanese
[Python, ObsPy] I wrote a beach ball with Matplotlib + ObsPy
I wrote the basic operation of matplotlib with Jupyter Lab
I wrote Fizz Buzz in Python
I wrote Gray Scale in Pytorch
I wrote the queue in Python
I wrote the stack in Python
Matplotlib memorandum
vim-quickrun-qo wrote
Matplotlib gallery
Matplotlib memo
I wrote the selection sort in C
I wrote unit tests for various languages
I wrote the code for Gibbs sampling
matplotlib summary
[Python beginner] I collected the articles I wrote
I want to embed Matplotlib in PySimpleGUI
I wrote Project Euler 1 in one liner.
I wrote the sliding wing in creation.
I wrote gxredis to use redis-py safely
Why can't I install matplotlib in python! !!
I want to make matplotlib a dark theme
I wrote an IPython Notebook-like Tkinter wrapper [Python]
A memo that I wrote a quicksort in Python
When I try matplotlib in Python, it says'cairo.Context'
I want to display multiple images with matplotlib.
I wrote a class in Python3 and Java
I wrote "Introduction to Effect Verification" in Python
I wrote a design pattern in kotlin Prototype
I wrote an IPython Notebook-like Gtk wrapper [Python]
I wrote a script to upload a WordPress plugin
I wrote the hexagonal architecture in go language
I wrote a Japanese parser in Japanese using pyparsing.