我想在python中更改y轴刻度。我正在使用代码
public class DBUtil {
public static Connection createConnection(){
try{
Connection connection = (Connection) DriverManager.
getConnection("jdbc:mysql://localhost:3306/testdb",
"root", "");
System.out.println("Connected");
return connection;
}catch(Exception e) {
System.out.println("Connection Failed");
System.out.println(e);
}
}
public static void closeConnection(Connection conn) {
conn.close();
}
}
但所有y轴标签都出现在彼此顶部的一个地方
答案 0 :(得分:1)
从这个example中大量借用,下面的代码演示了在一个图上有两个图的可能方法。
import pylab as plt
fig, ax1 = plt.subplots()
y1 = [0,1,2,3,4,5,6,7,8,9,10]
labels = [0.30,0.29,0.28,0.27,0.26,0.25,0.24,0.23,0.22,0.21,0.20]
ax1.plot(labels, y1, 'b-')
ax1.set_xlabel('labels')
# Make the y-axis label, ticks and tick labels match the line color.
ax1.set_ylabel('y1', color='b', rotation="horizontal")
ax1.tick_params('y', colors='b')
ax2 = ax1.twinx()
y2 = [90,40,65,12,23,43,54,13,42,53,63]
ax2.plot(labels, y2, 'r-')
ax2.set_ylabel('y2', color='r', rotation="horizontal")
ax2.tick_params('y', colors='r')
fig.tight_layout()
plt.show()