Draw a loose graph with matplotlib

Speaking of graphs in python, it is matplotlib, but since it is a bit bad, I think I use seaborn to draw a beautiful graph.

seaborn can easily draw beautiful graphs, but in the presentation materials of the study session We recommend a library that draws handwritten graphs.

How to use

XKCD-stlye seems to be built into matplotlib, so Just write one line at the beginning.

import matplotlib.pyplot as plt
plt.xkcd()

sample

Here are some of the graphs that look like. There are many other samples on the matplotlib glallery page (http://matplotlib.org/xkcd/gallery.html).

Line graph

x = np.arange(-3, 3, 0.1)
y = np.sin(x)
plt.plot(x, y, c='lightskyblue', label='y = sin(x)')
plt.plot([-3, 3], [-1, 1], c='lightcoral', label='y = 1/3x')
plt.legend()
plt.title('Line Plot')
plt.xlabel('x')
plt.ylabel('y')
plt.show()

Normal

output_1_0.png

Loose fluffy version

output_2_0.png

Scatter plot

N = 50
x = np.random.rand(N)
y = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2
plt.title('Scatter Plot')
plt.scatter(x, y, s=area, alpha=0.5, c='gold')
plt.show()

Normal

output_1_1.png

Loose fluffy version

output_2_1.png

histogram

plt.hist(np.random.randn(1000), color='yellowgreen')
plt.title('Histgram')
plt.show()

Normal

output_1_2.png

Loose fluffy version

output_2_2.png

pie chart

x = np.array([0.2, 0.4, 0.15, 0.25])
labels = ['Melon', 'Banana', 'Grape', 'Apple']
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
plt.pie(x, autopct='%d%%', labels=labels, colors=colors)
plt.axis('equal')
plt.title('Pie Chart')
plt.show()

Normal

output_1_3.png

Loose fluffy version

output_2_3.png

Recommended Posts

Draw a loose graph with matplotlib
Draw a graph with NetworkX
Draw a graph with networkx
Draw a graph with matplotlib from a csv file
Draw a graph with Julia + PyQtGraph (2)
[Python] How to draw a line graph with Matplotlib
Draw a graph with Julia + PyQtGraph (1)
Draw a graph with Julia + PyQtGraph (3)
Draw a graph with pandas + XlsxWriter
Draw a graph with PySimple GUI
Study math with Python: Draw a sympy (scipy) graph with matplotlib
How to draw a graph using Matplotlib
Draw a graph with PyQtGraph Part 1-Drawing
Create a graph with borders removed with matplotlib
Band graph with matplotlib
Draw a graph with Japanese labels in Jupyter
How to draw a 2-axis graph with pyplot
Draw a graph with PyQtGraph Part 3-PlotWidget settings
Draw a graph by processing with Pandas groupby
[Python] Draw a directed graph with Dash Cytoscape
Draw a graph with PyQtGraph Part 4-PlotItem settings
Draw a graph with PyQtGraph Part 6-Displaying a legend
(Matplotlib) I want to draw a graph with a size specified in pixels
How to draw a bar graph that summarizes multiple series with matplotlib
Graph Excel data with matplotlib (1)
Graph drawing method with matplotlib
Graph Excel data with matplotlib (2)
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
Forcibly draw something like a flowchart with Python, matplotlib
Draw a graph with PyQtGraph Part 2--Detailed plot settings
[Python] How to draw a scatter plot with Matplotlib
A python graphing manual with Matplotlib.
Draw Japanese with matplotlib on Ubuntu
Draw a beautiful circle with numpy
Multiple file processing with Kivy + Matplotlib + Draw Graph on GUI
Draw retention rate graph in Matplotlib
Let's make a graph with python! !!
[Visualization] I want to draw a beautiful graph with Plotly
Easy to draw graphs with matplotlib
Make a nice graph with plotly
Draw Lyapunov Fractal with Python, matplotlib
Write a stacked histogram with matplotlib
Easily draw a map with matplotlib.basemap
[Python] Set the graph range with matplotlib
[PyQt] Display a multi-axis graph with QtChart
Try drawing a normal distribution with matplotlib
Draw a heart in Ruby with PyCall
Make a partially zoomed figure with matplotlib
Draw a Mandelbrot set with Brainf * ck
Draw hierarchical axis labels with matplotlib + pandas
Graph trigonometric functions with numpy and matplotlib
Simply draw a graph by specifying a file
Write a nice pie chart with matplotlib
Draw a graph that can be moved around with HoloViews and Bokeh
Animation with matplotlib
Japanese with matplotlib
matplotlib graph album
Animation with matplotlib
Histogram with matplotlib
Animate with matplotlib
Draw a graph of a quadratic function in Python