Install matplotlib and display graph on Jupyter Notebook

I want to see data in an easy-to-understand manner with Jupyter Notebook

I was learning TensorFlow and was investigating the API, but I thought that it would be convenient if I could see it in a graph, so I tried using matplotlib. It is an installation method and a simple usage memo.

Below are links to articles related to the current environment and TensorFlow.

-Installing TensorFlow on Windows was easy even for Python beginners -[Explanation for beginners] TensorFlow basic syntax and concept -[Explanation for beginners] TensorFlow tutorial MNIST (for beginners) -Visualize TensorFlow tutorial MNIST (for beginners) with TensorBoard -TensorFlow API memo -[Introduction to TensorBoard] Visualize TensorFlow processing to deepen understanding

Install matplotlib with pip from Anaconda

1. Start the terminal from Anaconda Navigator

Launch Anaconda Navigator from the Windows menu. Select Environment from the menu, select the virtual environment, and start the terminal with "Open Terminal". 10.open_terminal_via_anaconda.JPG

2. Install matplotlib with pip

Just install with pip.

pip install matplotlib

20.install_matplotlib.JPG

Try matplotlib

Try the contents of Wikipedia as it is.

Line graph

import matplotlib.pyplot as plt
import numpy as np
a = np.linspace(0,10,100)
b = np.exp(-a)
plt.plot(a,b)
plt.show()

30.matplotlib01.JPG

histogram

import matplotlib.pyplot as plt
from numpy.random import normal,rand
x = normal(size=200)
plt.hist(x,bins=30)
plt.show()

30.matplotlib02.JPG

Scatter plot

import matplotlib.pyplot as plt
from numpy.random import rand
a = rand(100)
b = rand(100)
plt.scatter(a,b)
plt.show()

30.matplotlib03.JPG

3D graph

amazing···

from matplotlib import cm
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm)
plt.show()

30.matplotlib04.JPG

Check TensorFlow API

The original motivation for using matplotlib was TensorFlow API confirmation. As a bonus, I'm checking the functionality of TensorFlow's API truncated_normal like this.

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
x = sess.run(tf.truncated_normal([30000], stddev=0.1))
fig = plt.figure()
ax = fig.add_subplot(1,1,1)

ax.hist(x, bins=100)
ax.set_title('Histogram tf.truncated_normal')
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()

30.matplotlib05.JPG

Recommended Posts

Install matplotlib and display graph on Jupyter Notebook
Simply display a line graph on Jupyter Notebook
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Display the graph of tensorBoard on jupyter
Display histogram / scatter plot on Jupyter Notebook
[Jupyter Notebook memo] Display kanji with matplotlib
Install Anaconda on Mac and upload Jupyter (IPython) notebook to Anaconda Cloud
Graph drawing with jupyter (ipython notebook) + matplotlib + vagrant
How to install Fast.ai on Alibaba Cloud GPU and run it on Jupyter notebook
Easily launch jupyter notebook on AWS and access locally
Install octave_kernel on Jupyter [additional]
Display HTML in Jupyter notebook
Display PIL images on Jupyter
High charts on Jupyter notebook
View PDF on Jupyter Notebook
Real-time graph display by matplotlib
Run Jupyter Notebook on windows
Put Scipy + Matplotlib in Ubuntu on Vagrant and display the graph with X11 Forwarding
Read the csv file with jupyter notebook and write the graph on top of it
[Memo] Display Jupyter Notebook on PC in monospaced font (Mac)
Unable to display tensorboard in jupyter notebook on docker (solved)
Write charts in real time with Matplotlib on Jupyter notebook
Formatting with autopep8 on Jupyter notebook
matplotlib: Insert comment on timeline graph
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Steps to install matplotlib on Mac
Build and install OpenCV on Windows
Run azure ML on jupyter notebook
Jupyter Notebook: 4 banal tips and tricks
Install fabric on Ubuntu and try
Jupyter does not show matplotlib graph
matplotlib log scale display and grid display
Try running Jupyter Notebook on Mac
Install easy_install and pip on windows
Until you install and run matplotlib
Day 65 I installed matplotlib to draw graphs on my Jupyter notebook.
Resolve garbled Japanese characters in matplotlib of Jupyter Notebook on Docker
Real-time display of video acquired from webcam on Jupyter notebook (Python3)
Install matplotlib on OS X El Capitan
Jupyter Notebook does not show matplotlib graphs
Install wsl2 and master linux on windows
Use Jupyter Lab and Jupyter Notebook with EC2
Make Jupyter Notebook a service on CentOS
Try SVM with scikit-learn on Jupyter Notebook
Start jupyter notebook on GPU server (remote server)
Understand how to display images on Jupyter (utilization of imshow / matplotlib of OpenCV)
I want to display an image on Jupyter Notebook using OpenCV (mac)
Display Matplotlib xy graph in PySimple GUI.
Install and launch k3s on Manjaro Linux
Install and Configure TigerVNC server on Linux
Clone the github repository on jupyter notebook
Jupyter Notebook basic operations and shortcut keys
GPU check of PC on jupyter notebook
Linking python and JavaScript with jupyter notebook
Install ubuntu on 32bit UEFI Ultra Notebook
Build jupyter notebook on remote server (CentOS)
Install Puppet Master and Client on Ubuntu 16.04
Use vim keybindings on Docker-launched Jupyter Notebook