当前位置:网站首页>Matplotlib double Y axis + adjust legend position
Matplotlib double Y axis + adjust legend position
2022-07-02 05:39:00 【Bluestone horizontal knife riding horse】
from matplotlib.pyplot import rcParams
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib
# Import data 、 Processing data ( This step can be ignored by readers )
dataframe = pd.read_csv('D:/ Epidemic forecast /USA.csv',usecols=[1])#658 strip
dataset_old = dataframe.values
diff1=[]
diff1=dataset_old .diff()
# Prevent Chinese miscoding
rcParams['font.sans-serif'] = 'kaiti'
# Generate a time series
time =pd.to_datetime(np.arange(0,658), unit='D',
origin=pd.Timestamp('2020-1-21'))
# Create a canvas
fig=plt.figure(figsize=(18,6))#figsize For canvas size
# Add a sub view on the canvas
ax1=fig.add_subplot(111)
ax1.plot(time,dataset_old,color='#1bb9f6',linestyle='--')
ax1.set_title(' The cumulative number of infections in the United States and the number of new infections per day ',fontsize=20)
ax1.set_xlabel(' date / God ',fontsize=20)# Set up x Axis
ax1.set_ylabel(' Cumulative number of infections / Ten million ',fontsize=20)# Set the left side y Axis
ax2=ax1.twinx()# Very important
ax2.plot(time,diff1,color='#9d5dfc',linestyle='-')
ax2.set_ylabel(' New infections per day / people ',fontsize=20)# Set the... On the right y Axis
fig.legend([" Cumulative number of confirmed cases ",' New infections per day '],fontsize=20,loc='upper left',bbox_to_anchor=(0.13,0.9))
#loc Is the legend position ,bbox_to_anchor(n1,n2),n1 Move left and right ,n2 Move up and down , Manually adjust the legend position
give the result as follows 
边栏推荐
- Thread pool overview
- [personal test] copy and paste code between VirtualBox virtual machine and local
- Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
- Pytorch Chinese document
- Sliding window on the learning road
- Gee series: Unit 2 explore datasets
- Fabric. JS compact JSON
- Visual Studio导入
- 数据的储存
- Financial portal related information
猜你喜欢

2022-2-15 learning xiangniuke project - Section 8 check login status

Using QA band and bit mask in Google Earth engine

2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
![Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]](/img/78/a17034d4b77d5c0dbe741f84a8ecd7.jpg)
Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]

Fabric. JS compact JSON

Fabric. JS upload local image to canvas background

RGB 无限立方体(高级版)

RGB infinite cube (advanced version)

Fabric. JS activation input box

Fabric. JS right click menu
随机推荐
延时队列两种实现方式
2022-2-14 learning xiangniuke project - Section 6 displays login information
Alibaba: open source and self-developed liquid cooling data center technology
Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]
Gee: remote sensing image composite and mosaic
RGB 无限立方体(高级版)
Youth training camp -- database operation project
如何写出好代码 — 防御式编程指南
Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share
Typora installation (no need to enter serial number)
Pytorch Basics
Fabric. JS round brush
【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
ThreadLocal memory leak
Zzuli:1061 sequential output of digits
中小型项目手撸过滤器实现认证与授权
[Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
Using QA band and bit mask in Google Earth engine
【技术随记-08】
Thread pool batch processing data