2

I've created a state map and would like to remove the x-axis and y-axis as these don't provided any value for this plot.

map_population_by_county = (
ggplot(map_population_by_county_data)
+ geom_map(aes(fill='Population2018'))
+ geom_label(aes(x = 'Longitude', y = 'Latitude', label='Population2018', size=2))
)
map_population_by_county

enter image description here

I expect that adding + theme(axis.text.x=element_blank()) should remove the axis and that I should similarly be able to modify more such as

+ theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
        axis.ticks.x=element_blank())

But when I add + theme(axis.text.x=element_blank()) I receive an error

map_population_by_county = (
ggplot(map_population_by_county_data)
+ geom_map(aes(fill='Population2018'))
+ geom_label(aes(x = 'Longitude', y = 'Latitude', label='Population2018', size=2))
+ theme(axis.text.x=element_blank())
)
map_population_by_county

  File "<ipython-input-23-45e23f30fc6a>", line 5
    + theme(axis.text.x=element_blank())
            ^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

Adding a double equals "==" doesn't seem right but I tried it and received a new error, NameError: name 'axis' is not defined

Is it possible that I am not importing the plotnine package correctly? In order for geom_point, etc. to work I had to import these specifically as from plotnine import ggplot, aes, geom_map, geom_text, geom_label in the jupyter notebook that I'm using. Using import plotnine as p9 or from plotnine import * would not even work for the map above. I've tried adding from plotnine import theme, but that didn't work.

windyvation
  • 497
  • 3
  • 13
  • 2
    try `axis_text_x`. You're using the `r` syntax where you can separate variable names with `.`, but they changed the parameter names in `python` to be separated with `_`. – cookesd Jan 04 '21 at 19:54
  • Thanks @cookesd ! When I used `from plotnine import *` and changed the `.` to the `_` then it worked! – windyvation Jan 04 '21 at 19:59

1 Answers1

2

As suggested by @cookesd - replacing axis.text.x (the R ggplot formulation) with axis_text_x for python plotnine resolved this issue.

In python the parameter names need to be separated with a _

windyvation
  • 497
  • 3
  • 13