[英]How to make this chart easier to read?
I want to know how to get my x axis labels to display bigger so that the team labels aren't overlapping.我想知道如何让我的 x 轴标签显示得更大,以便团队标签不重叠。 I'm sure it's just a matter of configuring the chart size
我确定这只是配置图表大小的问题
My code:我的代码:
plt.plot(prem_data.Team, prem_data.attack_scored,'o')
plt.plot(prem_data.Team, prem_data.defence_saves)
plt.xlabel("Team")
plt.ylabel("Attack goals scored & Defence tackles")
plt.legend(["attack scored", "defence saved"])
plt.show()
I can imagine there being two mutually non-exclusive solutions.我可以想象有两种互不排斥的解决方案。
Directly alter the size of the font.直接改变字体大小。 This can be achieved via calling
plt.rcParams.update({'font.size': <font_size>})
, assuming that you have imported matplotlib.pyplot
under the alias plt
, as you have done in the source code provided.这可以通过调用
plt.rcParams.update({'font.size': <font_size>})
,假设您已经在别名plt
下导入了matplotlib.pyplot
,就像您在提供的源代码中所做的那样。 You would probably want to set the <font_size>
to be small to prevent overlapping labels, but this would require some experimentation.您可能希望将
<font_size>
设置为小以防止标签重叠,但这需要进行一些实验。
Increase the size of the figure.增加图形的大小。 This can be done in a number of ways, but perhaps the simplest method you can implement with minimal edits to your current code would be to use the command
plt.rcParams["figure.figsize"] = <fig_size>
where <fig_size>
is a tuple specifying the size of the figure in inches, such as (10, 5)
.这可以通过多种方式完成,但也许您可以通过对当前代码进行最少编辑来实现的最简单方法是使用命令
plt.rcParams["figure.figsize"] = <fig_size>
其中<fig_size>
是以英寸为单位指定图形大小的元组,例如(10, 5)
。
With some trial and error, you should be able to manipulate the size of the font and the figure to produce a plot with improved readability.通过一些试验和错误,您应该能够操纵字体和图形的大小以生成具有更高可读性的绘图。
Note: The method for altering figure size I introduced above is not the most conventional way to go about this problem.注意:我上面介绍的改变图形大小的方法不是解决这个问题的最传统的方法。 Instead, it is much more common to use
matplotlib.pyplot.figure
or similar variants.相反,使用
matplotlib.pyplot.figure
或类似的变体更为常见。 For more information, I recommend that you check out this thread and the documentation .有关更多信息,我建议您查看此线程和文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.