A memo for making a figure that can be posted to a journal with matplotlib

I'm sorry it's not a good article, but I wrote it down because I always forget it and have a hard time when I correct the figure before submitting the paper.

Specify the size of the figure in the first place

fig = plt.figure(figsize=(15,3))

Put text inside and outside the figure

Coordinate specification by relative ratio

ax.annotate('Test', xy=(0, 1.1), xycoords='axes fraction', fontsize=16)

Coordinate specification at data points

ax.annotate('Test', xy=(0, 0.1), xycoords='data', fontsize=16)

Supplement

Above ax. Somehow

ax = fig.add_subplot(1,1,1)

It is ax. The same notation is used below.

Erase the unnecessary parts of the x-axis value.

ax.xaxis.set_ticklabels([])

Erase tick

ax.axes.get_xaxis().set_ticks([])

Make the notation of the numerical value of the axis like 0.1, 0.5

from matplotlib.ticker import MultipleLocator, FormatStrFormatter
ax.xaxis.set_major_formatter(FormatStrFormatter("%.1f"))

When the y-axis number is long

ax.yaxis.set_major_formatter(FormatStrFormatter("%1.e"))

Reverse the direction of the axis

plt.gca().invert_xaxis()

Expand the values on the axis as appropriate

plt.tick_params(labelsize=20)

Change the aspect ratio (regardless of the data).

In this case, it is necessary to acquire the data ratio of plot before using it. That is, in the case of 0.7, after ax.plot

ax.set_aspect(0.7/ax.get_data_ratio())

The color bar is so long that I don't like it, so I just shorten it.

colorbar(bar,shrink=0.3)

Write a label with a horizontal color bar

cbar=colorbar(bar, orientation='horizontal')
cbar.set_label(‘color label',size=14)

temp1.jpg

Logarithmic color

from matplotlib.colors import LogNorm
bar=ax.imshow(stdall,vmin=0.01,vmax=1.0,extent[w[0],w[-1],2250.0,6750.0],\
interpolation='nearest',cmap="hot",norm=LogNorm())

temp2.jpg

Add a color bar tick

 cbar=colorbar(bar, orientation='horizontal',ticks=\
[0.05,0.06,0.07,0.08,0.09,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])

Match the size of the color bars to the figure

from mpl_toolkits.axes_grid1 import make_axes_locatable

divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(a, cax=cax)

Make sure that the label below does not stick out

fig.subplots_adjust(bottom=0.2)

Output as PDF to prevent strange margins and label breaks.

plt.savefig("figure1.pdf", bbox_inches="tight", pad_inches=0.0)

Recommended Posts

A memo for making a figure that can be posted to a journal with matplotlib
A memo when creating an environment that can be debugged with Lambda @ Edge for the time being
Convert images from FlyCapture SDK to a form that can be used with openCV
I tried to make a memo app that can be pomodoro, but a reflection record
Let's make a diagram that can be clicked with IPython
[Python] Make a graph that can be moved around with Plotly
[Python] A memo that I tried to get started with asyncio
Make a Spinbox that can be displayed in Binary with Tkinter
I made a shuffle that can be reset (reverted) with Python
Make a currency chart that can be moved around with Plotly (2)
Create a poster with matplotlib to visualize multiplication tables that remember multiplication
Comparison of 4 styles that can be passed to seaborn with set_context
Make a Spinbox that can be displayed in HEX with Tkinter
Make a currency chart that can be moved around with Plotly (1)
Understand the probabilities and statistics that can be used for progress management with a python program
I created a template for a Python project that can be used universally
Memo to ask for KPI with python
How to make a rock-paper-scissors bot that can be easily moved (commentary)
Create a web app that can be easily visualized with Plotly Dash
A memo that allows you to change Pineapple's Python environment with pyenv
Make a partially zoomed figure with matplotlib
Mathematical optimization that can be used for free work with Python + PuLP
How to draw a bar graph that summarizes multiple series with matplotlib
Draw a graph that can be moved around with HoloViews and Bokeh
Linux screen distribution on Ubuntu Memo that wants to be a Linux screen distribution YouTuber
Match the colorbar to the figure with matplotlib
I wanted to quickly create a mail server that can be used freely with postfix + dovecot on EC2
A class for PYTHON that can be operated without being aware of LDAP
I want to create a priority queue that can be updated in Python (2.7)
A personal memo of Pandas related operations that can be used in practice
Format DataFrame data with Pytorch into a form that can be trained with NN
I made a familiar function that can be used in statistics with Python
How to install a Python library that can be used by pharmaceutical companies
[Hackathon] About making a tool that can be CD on Raspberry Pi [Convenient tool]
A story about making an x86 bootloader that can boot vmlinux with Rust
File types that can be used with Go
Functions that can be used in for statements
A memo that made a graph animated with plotly
Pretend to be a server with two PCs
List packages that can be updated with pip
[Python] Introduction to web scraping | Summary of methods that can be used with webdriver
How to create a property of relations that can be prefetch_related by specific conditions
File sharing server made with Raspberry Pi that can be used for remote work
A mechanism to call a Ruby method from Python that can be done in 200 lines
A memo connected to HiveServer2 of EMR with python
[Python] How to draw a line graph with Matplotlib
Add information to the bottom of the figure with Matplotlib
Color list that can be set with tkinter (memorial)
Python knowledge notes that can be used with AtCoder
A server that echoes data POSTed with flask / python
[Python] A memo to write CSV vertically with Pandas
Convenient to use matplotlib subplots in a for statement
I want to manually create a legend with matplotlib
A memo that I touched the Datastore with python
I made a tool to automatically generate a state transition diagram that can be used for both web development and application development
[Python] How to create a 2D histogram with Matplotlib
Making a paper craft on Linux/macOS with OSS Memo
Limits that can be analyzed at once with MeCab
[Python] How to draw a scatter plot with Matplotlib
[Python] Road to a snake charmer (5) Play with Matplotlib
How to set up a simple SMTP server that can be tested locally in Python