例如,当我尝试运行时:
mpl.rcParams['font.family'] = 'serif'
plt.rcParams['figure.figsize'] = [15,7]
plt.plot(data['flow-time'], data['staticpressurerecovery'])
plt.xlabel('Time [s]')
plt.ylabel('Static Pressure Recovery [-]')
plt.title('McD13_4S3 Plenum: Performance Coefficient ')
plt.ylim((0.33, 0.4))
plt.grid()
plt.show()
在Jupyter笔记本中,出现以下错误消息:
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1331: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
删除fontList.cache
,fontList.json
和fontList.py3.cache
取消注释matplotlibrc
文件的字体系列相关部分
使用matplotlib
和pip uninstall matplotlib
pip install matplotlib
没有任何问题可以解决。现在我获取不同字体的唯一可能方法是使用LaTeX作为后端,但这很慢且不必要。
有什么想法我接下来可以尝试吗?
编辑:我正在使用Windows 10,所以没有为我使用apt-get
。这似乎是解决这些问题的常用方法,但是我做不到。看来这些解决方案只是将Microsoft字体添加到Linux字体管理器中,所以由于我已经在Microsoft计算机上,所以它甚至可能不相关。
最小工作示例:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['font.serif'] = 'Computer Modern'
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.show()
在fontList.json
中,Computer Modern被列为可用字体。
答案 0 :(得分:0)
我有同样的问题。对于我来说,将我的matplotlib版本从改回import psycopg2
try:
connect_str = "dbname='mydatabase' user='myuser' host='localhost' " + \
"password='mypassword'"
# establish a connection
conn = psycopg2.connect(connect_str)
# cursor that to execute queries
cursor = conn.cursor()
# start at the beginning, select the first text field
sql = "SELECT textfield FROM mytable WHERE id=1"
cursor.execute(sql)
rows = cursor.fetchall()
print(rows)
cont = raw_input('Type Accept Continue')
# if user accepts it is ok to proceed, advance to display data from next textfield
if cont=='Accept':
print("Accepted")
sqn = "SELECT textfield, nextitem FROM mytable WHERE id=2"
cursor.execute(sqn)
rows = cursor.fetchall()
print(rows)
result_set = cursor.fetchall()
#ideally, this should grab the integer in the [nextitem] column from last query and select the row corresponding to the integer
for row in result_set:
#print the integer to test the value and make sure it is correct
print "%s" % (row["nextitem"])
#attempt to assign this integer to a variable?
x=["nextitem"]
#attempt feeding the integer previously selected in [nextitem] into the next query
sqv = "SELECT text FROM mytable WHERE id=%s"
cursor.execute(sqv,x)
result = cursor.fetchall()
print(result)
else:
print("Rejected or Not Accepted")
except Exception as e:
print("No Connection Available")
print(e)
就可以解决此问题。您需要先1.5.3
,然后pip uninstall matplotlib
。
更多情况下,我在装有Amazon EC2的齐柏林飞艇笔记本上使用pip install matplotlib==1.5.3
。某种程度上,安装的matplotlib版本是ggplot
。
更改版本后,错误消失了