簡體   English   中英

需要固定圖形的x軸和y軸,以便我可以清楚地看到表示形式

[英]Need to fix x-axis and y-axis for a graph so that I can clearly see the representation

我在python(spyder)中將圖像生成為輸出。 y軸上的數字都雜亂無章,無法讀取。 如何使圖清晰,以使該y軸上的每個數字都清晰可見。 我還想更改x軸的長度,以便用戶可以了解每個條在x軸上對應的值。 在這一點上確實很難閱讀。

因此,是的,我確實想如上所述以自己的方式更改x軸和y軸。 請幫我解決一下這個。 我正在使用import matplotlib.pyplot作為plt,所以請不要更改它。 請點擊下面的鏈接獲取我得到的圖表的圖像。

http://i57.tinypic.com/6g8obb.png

這是代碼:

tempArray = myNumpRead[:,1]
barh = plt.subplot(111)
width = 0.8
barh.barh(range(len(states)), tempArray)
barh.set_ylim(-width,len(states)+width)
barh.set_yticks(np.arange(len(states)) + width/2)
barh.set_yticklabels(states, rotation=0)
plt.title('Population by State')
plt.xlabel('Population')
plt.ylabel('State Ticker')
plt.grid(True)
plt.show()

感謝您的幫助。

您的問題很難回答,因為沒有您的變量就無法復制您的代碼,而且我在您提供的鏈接中看不到圖片。

但是,您可能會要求增加圖形的寬度。 可以這樣做:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 1)
y = x**2

fig = plt.figure(figsize=(10, 3)) # the 10 here is width, the 3 is height
ax = fig.add_subplot(111)
ax.plot(x, y)
plt.show(fig)

讓我知道是否有幫助。 如果您需要進一步的幫助,請發布代碼,該代碼可以重現您的問題,而無需我們提供變量。 即。 編寫可以獨立運行的代碼。

看圖片后編輯

將代碼更改為以下代碼是否可以解決問題?

tempArray = myNumpRead[:,1]
fig = plt.figure(figsize=(5, 15)) # Change these numbers here to suit what you want
ax = fig.add_subplot(111)
width = 0.8
ax.barh(range(len(states)), tempArray)
ax.set_ylim(-width,len(states)+width)
ax.set_yticks(np.arange(len(states)) + width/2)
ax.set_yticklabels(states, rotation=0)
ax.set_title('Population by State')
ax.set_xlabel('Population')
ax.set_ylabel('State Ticker')
ax.grid(True)
plt.show(fig)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM