Issue
I'm trying to add an axline
with slope=1
to each of a series of subplots.
- I'm following the
axline
example but it does not seem to work with my modifications. - This appears to be the closest question on SO, but doesn't answer my question
Code attempts and errors
01. As in axline
example:
import matplotlib.pyplot as plt
import pandas as pd
fig, axes = plt.subplots(4, 2, sharex=True, sharey=True, figsize=(12, 10))
plt.xlim([-5, 10])
plt.ylim([-5, 10])
for ax in axes.flat:
ax.axline((0,0), slope=1, color='r', linewidth=2, linestyle='--')
'AxesSubplot' object has no attribute 'axline'
02. Within each subplot:
fig, axes = plt.subplots(4, 2, sharex=True, sharey=True, figsize=(12, 10))
row, col = 0, 0
for q in questions: # questions defined by my data
question_scatter(df, q, row, col) # UDF to create a scatter plot in axes[row, col]
axes[row, col].axline((0,0), slope=1, color='r', linewidth=2, linestyle='--')
if row < 3:
row += 1
else:
row = 0
col += 1
'AxesSubplot' object has no attribute 'axline'
03. Apply globally:
fig, axes = plt.subplots(4, 2, sharex=True, sharey=True, figsize=(12, 10))
axes.axline((0,0), slope=1, color='r', linewidth=2, linestyle='--')
numpy.ndarray' object has no attribute 'axline'
Solution
As @suraj shourie points out, my first solution works if I upgrade matplotlib
to v3.3.0
.
For completeness:
$ pip install -U matplotlib==3.3.0
import matplotlib.pyplot as plt
import pandas as pd
fig, axes = plt.subplots(4, 2, sharex=True, sharey=True, figsize=(12, 10))
for ax in axes.flat:
ax.axline((0,0), slope=1, color='r', linewidth=2, linestyle='--')
Answered By - alexwhitworth
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.