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

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.
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 _
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With